Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
sgxwallet
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
董子豪
sgxwallet
Commits
3074ad6a
Unverified
Commit
3074ad6a
authored
Feb 17, 2020
by
Stan Kladko
Committed by
GitHub
Feb 17, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #53 from skalenetwork/SKALE-2167-tests
Skale 2167 tests
parents
2e95b40d
bc527bf2
Changes
17
Show whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
1086 additions
and
1105 deletions
+1086
-1105
BLSCrypto.cpp
BLSCrypto.cpp
+9
-10
BLSCrypto.h
BLSCrypto.h
+2
-2
DKGCrypto.cpp
DKGCrypto.cpp
+3
-3
Dockerfile
Dockerfile
+0
-2
DockerfileSimulation
DockerfileSimulation
+2
-2
Makefile.am
Makefile.am
+4
-2
SEKManager.cpp
SEKManager.cpp
+5
-1
SGXWalletServer.cpp
SGXWalletServer.cpp
+11
-5
start.sh
docker/start.sh
+26
-8
docker-compose.yml
run_sgx/docker-compose.yml
+2
-2
docker-compose.yml
run_sgx_sim/docker-compose.yml
+2
-2
docker_test.py
scripts/docker_test.py
+17
-12
Makefile.in
secure_enclave/Makefile.in
+37
-85
sgxwallet.c
sgxwallet.c
+5
-4
stubclient.h
stubclient.h
+19
-19
tests.bash
tests.bash
+22
-0
testw.cpp
testw.cpp
+920
-946
No files found.
BLSCrypto.cpp
View file @
3074ad6a
...
@@ -314,22 +314,21 @@ bool bls_sign(const char* _encryptedKeyHex, const char* _hashHex, size_t _t, siz
...
@@ -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
*
encryptBLSKeyShare2Hex
(
int
*
errStatus
,
char
*
err_string
,
const
char
*
_key
)
{
char
*
keyArray
=
(
char
*
)
calloc
(
BUF_LEN
,
1
);
auto
keyArray
=
make_shared
<
vector
<
char
>>
(
BUF_LEN
,
0
);
uint8_t
*
encryptedKey
=
(
uint8_t
*
)
calloc
(
BUF_LEN
,
1
);
auto
encryptedKey
=
make_shared
<
vector
<
uint8_t
>>
(
BUF_LEN
,
0
);
char
*
errMsg
=
(
char
*
)
calloc
(
BUF_LEN
,
1
);
auto
errMsg
=
make_shared
<
vector
<
char
>>
(
BUF_LEN
,
0
);
strncpy
((
char
*
)
keyArray
,
(
char
*
)
_key
,
BUF_LEN
);
strncpy
(
keyArray
->
data
(),
_key
,
BUF_LEN
);
*
errStatus
=
-
1
;
*
errStatus
=
-
1
;
unsigned
int
encryptedLen
=
0
;
unsigned
int
encryptedLen
=
0
;
//status = encrypt_key(eid, errStatus, errMsg, keyArray, encryptedKey, &encryptedLen);
//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
)
{
if
(
DEBUG_PRINT
)
{
spdlog
::
info
(
"errStatus is {}"
,
*
errStatus
);
spdlog
::
info
(
"errStatus is {}"
,
*
errStatus
);
spdlog
::
info
(
" errMsg is "
,
errMsg
);
spdlog
::
info
(
" errMsg is "
,
errMsg
->
data
()
);
}
}
if
(
status
!=
SGX_SUCCESS
)
{
if
(
status
!=
SGX_SUCCESS
)
{
...
@@ -339,13 +338,13 @@ char *encryptBLSKeyShare2Hex(int *errStatus, char *err_string, const char *_key)
...
@@ -339,13 +338,13 @@ char *encryptBLSKeyShare2Hex(int *errStatus, char *err_string, const char *_key)
}
}
if
(
*
errStatus
!=
0
)
{
if
(
*
errStatus
!=
0
)
{
throw
RPCException
(
-
666
,
errMsg
);
throw
RPCException
(
-
666
,
errMsg
->
data
()
);
}
}
char
*
result
=
(
char
*
)
calloc
(
2
*
BUF_LEN
,
1
);
char
*
result
=
(
char
*
)
calloc
(
2
*
BUF_LEN
,
1
);
carray2Hex
(
encryptedKey
,
encryptedLen
,
result
);
carray2Hex
(
encryptedKey
->
data
()
,
encryptedLen
,
result
);
return
result
;
return
result
;
}
}
...
...
BLSCrypto.h
View file @
3074ad6a
...
@@ -49,8 +49,8 @@ EXTERNC bool hex2carray2(const char * _hex, uint64_t *_bin_len,
...
@@ -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
#endif //SGXWALLET_BLSCRYPTO_H
DKGCrypto.cpp
View file @
3074ad6a
...
@@ -146,7 +146,8 @@ vector <vector<string>> get_verif_vect(const char* encryptedPolyHex, int t, int
...
@@ -146,7 +146,8 @@ vector <vector<string>> get_verif_vect(const char* encryptedPolyHex, int t, int
// printf(" %d ", encr_dkg_poly[i] );
// printf(" %d ", encr_dkg_poly[i] );
}
}
uint32_t
len
;
uint32_t
len
=
0
;
if
(
!
is_aes
)
if
(
!
is_aes
)
status
=
get_public_shares
(
eid
,
&
err_status
,
errMsg1
,
encr_dkg_poly
,
len
,
public_shares
,
t
,
n
);
status
=
get_public_shares
(
eid
,
&
err_status
,
errMsg1
,
encr_dkg_poly
,
len
,
public_shares
,
t
,
n
);
else
{
else
{
...
@@ -170,7 +171,7 @@ vector <vector<string>> get_verif_vect(const char* encryptedPolyHex, int t, int
...
@@ -170,7 +171,7 @@ vector <vector<string>> get_verif_vect(const char* encryptedPolyHex, int t, int
vector
<
string
>
G2_strings
=
SplitString
(
public_shares
,
','
);
vector
<
string
>
G2_strings
=
SplitString
(
public_shares
,
','
);
vector
<
vector
<
string
>>
pub_shares_vect
;
vector
<
vector
<
string
>>
pub_shares_vect
;
for
(
in
t
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
(),
':'
);
vector
<
string
>
koef_str
=
SplitString
(
G2_strings
.
at
(
i
).
c_str
(),
':'
);
pub_shares_vect
.
push_back
(
koef_str
);
pub_shares_vect
.
push_back
(
koef_str
);
}
}
...
@@ -382,7 +383,6 @@ vector<string> GetBLSPubKey(const char * encryptedKeyHex){
...
@@ -382,7 +383,6 @@ vector<string> GetBLSPubKey(const char * encryptedKeyHex){
int
err_status
=
0
;
int
err_status
=
0
;
uint64_t
dec_key_len
;
uint64_t
dec_key_len
;
uint8_t
encr_bls_key
[
BUF_LEN
];
uint8_t
encr_key
[
BUF_LEN
];
uint8_t
encr_key
[
BUF_LEN
];
if
(
!
hex2carray
(
encryptedKeyHex
,
&
dec_key_len
,
encr_key
)){
if
(
!
hex2carray
(
encryptedKeyHex
,
&
dec_key_len
,
encr_key
)){
throw
RPCException
(
INVALID_HEX
,
"Invalid encryptedKeyHex"
);
throw
RPCException
(
INVALID_HEX
,
"Invalid encryptedKeyHex"
);
...
...
Dockerfile
View file @
3074ad6a
...
@@ -7,7 +7,6 @@ COPY *.txt ./
...
@@ -7,7 +7,6 @@ COPY *.txt ./
COPY
*.c ./
COPY
*.c ./
COPY
*.am ./
COPY
*.am ./
COPY
*.hpp ./
COPY
*.hpp ./
COPY
*.sh ./
COPY
*.gmp ./
COPY
*.gmp ./
COPY
*.ac ./
COPY
*.ac ./
COPY
*.json ./
COPY
*.json ./
...
@@ -34,6 +33,5 @@ RUN ./configure
...
@@ -34,6 +33,5 @@ RUN ./configure
RUN
make
RUN
make
RUN
mkdir
/usr/src/sdk/sgx_data
RUN
mkdir
/usr/src/sdk/sgx_data
COPY
docker/start.sh ./
COPY
docker/start.sh ./
ENTRYPOINT
["/usr/src/sdk/start.sh"]
ENTRYPOINT
["/usr/src/sdk/start.sh"]
DockerfileSimulation
View file @
3074ad6a
...
@@ -7,7 +7,6 @@ COPY *.txt ./
...
@@ -7,7 +7,6 @@ COPY *.txt ./
COPY *.c ./
COPY *.c ./
COPY *.am ./
COPY *.am ./
COPY *.hpp ./
COPY *.hpp ./
COPY *.sh ./
COPY *.gmp ./
COPY *.gmp ./
COPY *.ac ./
COPY *.ac ./
COPY *.json ./
COPY *.json ./
...
@@ -33,6 +32,7 @@ RUN make
...
@@ -33,6 +32,7 @@ RUN make
RUN mkdir /usr/src/sdk/sgx_data
RUN mkdir /usr/src/sdk/sgx_data
COPY docker/start.sh ./
COPY docker/start.sh ./
ENTRYPOINT ["/usr/src/sdk/start.sh"]
ENTRYPOINT ["/usr/src/sdk/start.sh"]
Makefile.am
View file @
3074ad6a
...
@@ -44,8 +44,10 @@ secure_enclave.edl: secure_enclave/secure_enclave.edl
...
@@ -44,8 +44,10 @@ secure_enclave.edl: secure_enclave/secure_enclave.edl
##
##
#AM_CPPFLAGS += -g -Og
#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
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
...
...
SEKManager.cpp
View file @
3074ad6a
...
@@ -154,7 +154,11 @@ void gen_SEK(){
...
@@ -154,7 +154,11 @@ void gen_SEK(){
std
::
getline
(
std
::
cin
,
buffer
);
std
::
getline
(
std
::
cin
,
buffer
);
}
while
(
case_insensitive_match
(
confirm_str
,
buffer
));
//(strcmp(confirm_str.c_str(), buffer.c_str()) != 0);
}
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
());
LevelDB
::
getLevelDb
()
->
writeDataUnique
(
"SEK"
,
hexEncrKey
.
data
());
create_test_key
();
create_test_key
();
...
...
SGXWalletServer.cpp
View file @
3074ad6a
...
@@ -152,11 +152,13 @@ importBLSKeyShareImpl(const string &_keyShare, const string &_keyShareName, int
...
@@ -152,11 +152,13 @@ importBLSKeyShareImpl(const string &_keyShare, const string &_keyShareName, int
result
[
"errorMessage"
]
=
""
;
result
[
"errorMessage"
]
=
""
;
result
[
"encryptedKeyShare"
]
=
""
;
result
[
"encryptedKeyShare"
]
=
""
;
char
*
encryptedKeyShareHex
=
nullptr
;
try
{
try
{
// if ( !checkName(_keyShare, "BLS_KEY")){
// if ( !checkName(_keyShare, "BLS_KEY")){
// throw RPCException(INVALID_POLY_NAME, "Invalid BLSKey name");
// 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
)
{
if
(
encryptedKeyShareHex
==
nullptr
)
{
throw
RPCException
(
UNKNOWN_ERROR
,
""
);
throw
RPCException
(
UNKNOWN_ERROR
,
""
);
...
@@ -166,7 +168,7 @@ importBLSKeyShareImpl(const string &_keyShare, const string &_keyShareName, int
...
@@ -166,7 +168,7 @@ importBLSKeyShareImpl(const string &_keyShare, const string &_keyShareName, int
throw
RPCException
(
errStatus
,
errMsg
);
throw
RPCException
(
errStatus
,
errMsg
);
}
}
result
[
"encryptedKeyShare"
]
=
encryptedKeyShareHex
;
result
[
"encryptedKeyShare"
]
=
string
(
encryptedKeyShareHex
)
;
writeKeyShare
(
_keyShareName
,
encryptedKeyShareHex
,
index
,
n
,
t
);
writeKeyShare
(
_keyShareName
,
encryptedKeyShareHex
,
index
,
n
,
t
);
...
@@ -175,6 +177,10 @@ importBLSKeyShareImpl(const string &_keyShare, const string &_keyShareName, int
...
@@ -175,6 +177,10 @@ importBLSKeyShareImpl(const string &_keyShare, const string &_keyShareName, int
result
[
"errorMessage"
]
=
_e
.
errString
;
result
[
"errorMessage"
]
=
_e
.
errString
;
}
}
if
(
encryptedKeyShareHex
!=
nullptr
)
{
free
(
encryptedKeyShareHex
);
}
return
result
;
return
result
;
}
}
...
@@ -487,7 +493,7 @@ Json::Value getSecretShareImpl(const string& polyName, const Json::Value& public
...
@@ -487,7 +493,7 @@ Json::Value getSecretShareImpl(const string& polyName, const Json::Value& public
result
[
"errorMessage"
]
=
""
;
result
[
"errorMessage"
]
=
""
;
try
{
try
{
if
(
publicKeys
.
size
()
!=
n
){
if
(
publicKeys
.
size
()
!=
(
uint64_t
)
n
){
throw
RPCException
(
INVALID_DKG_PARAMS
,
"wrong number of public keys"
);
throw
RPCException
(
INVALID_DKG_PARAMS
,
"wrong number of public keys"
);
}
}
if
(
!
checkName
(
polyName
,
"POLY"
)){
if
(
!
checkName
(
polyName
,
"POLY"
)){
...
@@ -543,7 +549,7 @@ Json::Value dkgVerificationImpl(const string& publicShares, const string& ethKey
...
@@ -543,7 +549,7 @@ Json::Value dkgVerificationImpl(const string& publicShares, const string& ethKey
if
(
!
checkHex
(
SecretShare
,
SECRET_SHARE_NUM_BYTES
)){
if
(
!
checkHex
(
SecretShare
,
SECRET_SHARE_NUM_BYTES
)){
throw
RPCException
(
INVALID_HEX
,
"Invalid Secret share"
);
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"
);
throw
RPCException
(
INVALID_DKG_PARAMS
,
"Invalid length of public shares"
);
}
}
...
@@ -573,7 +579,7 @@ Json::Value createBLSPrivateKeyImpl(const string & blsKeyName, const string& eth
...
@@ -573,7 +579,7 @@ Json::Value createBLSPrivateKeyImpl(const string & blsKeyName, const string& eth
try
{
try
{
if
(
SecretShare
.
length
()
!=
n
*
192
){
if
(
SecretShare
.
length
()
!=
(
uint64_t
)
n
*
192
){
spdlog
::
info
(
"wrong length of secret shares - {}"
,
SecretShare
.
length
());
spdlog
::
info
(
"wrong length of secret shares - {}"
,
SecretShare
.
length
());
spdlog
::
info
(
"secret shares - {}"
,
SecretShare
);
spdlog
::
info
(
"secret shares - {}"
,
SecretShare
);
throw
RPCException
(
INVALID_SECRET_SHARES_LENGTH
,
"Invalid secret share length"
);
throw
RPCException
(
INVALID_SECRET_SHARES_LENGTH
,
"Invalid secret share length"
);
...
...
docker/start.sh
View file @
3074ad6a
#!/bin/bash
#!/bin/bash
source
/opt/intel/sgxsdk/environment
source
/opt/intel/sgxsdk/environment
export
LD_LIBRARY_PATH
=
${
LD_LIBRARY_PATH
}
:/opt/intel/sgxpsw/aesm/
cd
/usr/src/sdk
;
jhid
-d
/opt/intel/sgxpsw/aesm/aesm_service &
pid
=
$!
sleep
2
echo
$1
cd
/usr/src/sdk
;
./sgxwallet
$1
$2
$3
$4
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
run_sgx/docker-compose.yml
View file @
3074ad6a
version
:
'
3'
version
:
'
3'
services
:
services
:
sgxwallet
:
sgxwallet
:
image
:
skalenetwork/sgxwallet:latest
image
:
skalenetwork/sgxwallet:latest
_commit
ports
:
ports
:
-
"
1026:1026"
-
"
1026:1026"
-
"
1027:1027"
-
"
1027:1027"
...
@@ -17,6 +17,6 @@ services:
...
@@ -17,6 +17,6 @@ services:
max-size
:
"
10m"
max-size
:
"
10m"
max-file
:
"
4"
max-file
:
"
4"
restart
:
unless-stopped
restart
:
unless-stopped
command
:
-
s
command
:
-
t
run_sgx_sim/docker-compose.yml
View file @
3074ad6a
version
:
'
3'
version
:
'
3'
services
:
services
:
sgxwallet
:
sgxwallet
:
image
:
skalenetwork/sgxwalletsim:latest
image
:
skalenetwork/sgxwalletsim:latest
_commit
ports
:
ports
:
-
"
1026:1026"
-
"
1026:1026"
-
"
1027:1027"
-
"
1027:1027"
...
@@ -14,5 +14,5 @@ services:
...
@@ -14,5 +14,5 @@ services:
max-size
:
"
10m"
max-size
:
"
10m"
max-file
:
"
4"
max-file
:
"
4"
restart
:
unless-stopped
restart
:
unless-stopped
command
:
-
s -d -y
command
:
-
t
scripts/docker_test.py
View file @
3074ad6a
...
@@ -23,6 +23,12 @@
...
@@ -23,6 +23,12 @@
#
#
import
sys
,
os
,
subprocess
,
socket
,
time
import
sys
,
os
,
subprocess
,
socket
,
time
os
.
chdir
(
".."
)
os
.
chdir
(
".."
)
topDir
=
os
.
getcwd
()
+
"/sgxwallet"
topDir
=
os
.
getcwd
()
+
"/sgxwallet"
print
(
"Starting build push"
)
print
(
"Starting build push"
)
...
@@ -44,13 +50,18 @@ print("Running tests for branch " + BRANCH);
...
@@ -44,13 +50,18 @@ print("Running tests for branch " + BRANCH);
assert
subprocess
.
call
([
"docker"
,
"image"
,
"inspect"
,
FULL_IMAGE_NAME
])
==
0
;
assert
subprocess
.
call
([
"docker"
,
"image"
,
"inspect"
,
FULL_IMAGE_NAME
])
==
0
;
#assert subprocess.call(["docker", "run", "-v", topDir + "/sgx_data:/usr/src/sdk/sgx_data",
completedProcess
=
subprocess
.
run
([
"docker"
,
"run"
,
"-v"
,
topDir
+
"/sgx_data:/usr/src/sdk/sgx_data"
,
"-t"
,
# "-d", "--network=host", "skalenetwork/" + IMAGE_NAME +":" + TAG_POSTFIX]) == 0
"--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
)
assert
subprocess
.
call
([
"docker"
,
"rm"
,
"sgxwallet"
])
==
0
obj
.
terminate
()
assert
subprocess
.
call
([
"docker"
,
"run"
,
"-v"
,
topDir
+
"/sgx_data:/usr/src/sdk/sgx_data"
,
"-d"
,
obj
.
wait
()
"--name"
,
"sgxwallet"
,
"--network=host"
,
"skalenetwork/"
+
IMAGE_NAME
+
":"
+
TAG_POSTFIX
,
"-y"
])
==
0
time
.
sleep
(
5
);
time
.
sleep
(
5
);
...
@@ -74,9 +85,3 @@ s3.connect((address, 1028))
...
@@ -74,9 +85,3 @@ s3.connect((address, 1028))
s1
.
close
()
s1
.
close
()
s2
.
close
()
s2
.
close
()
s3
.
close
()
s3
.
close
()
secure_enclave/Makefile.in
View file @
3074ad6a
# Makefile.in generated by automake 1.1
6
.1 from Makefile.am.
# Makefile.in generated by automake 1.1
5
.1 from Makefile.am.
# @configure_input@
# @configure_input@
# Copyright (C) 1994-201
8
Free Software Foundation, Inc.
# Copyright (C) 1994-201
7
Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# gives unlimited permission to copy and/or distribute it,
...
@@ -137,16 +137,7 @@ am__v_at_0 = @
...
@@ -137,16 +137,7 @@ am__v_at_0 = @
am__v_at_1
=
am__v_at_1
=
DEFAULT_INCLUDES
=
-I
.@am__isrc@
DEFAULT_INCLUDES
=
-I
.@am__isrc@
depcomp
=
$(SHELL)
$(top_srcdir)
/depcomp
depcomp
=
$(SHELL)
$(top_srcdir)
/depcomp
am__maybe_remake_depfiles
=
depfiles
am__depfiles_maybe
=
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__mv
=
mv
-f
am__mv
=
mv
-f
COMPILE
=
$(CC)
$(DEFS)
$(DEFAULT_INCLUDES)
$(INCLUDES)
$(AM_CPPFLAGS)
\
COMPILE
=
$(CC)
$(DEFS)
$(DEFAULT_INCLUDES)
$(INCLUDES)
$(AM_CPPFLAGS)
\
$(CPPFLAGS)
$(AM_CFLAGS)
$(CFLAGS)
$(CPPFLAGS)
$(AM_CFLAGS)
$(CFLAGS)
...
@@ -375,8 +366,8 @@ Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
...
@@ -375,8 +366,8 @@ Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
*
config.status
*
)
\
*
config.status
*
)
\
cd
$(top_builddir)
&&
$(MAKE)
$(AM_MAKEFLAGS)
am--refresh
;;
\
cd
$(top_builddir)
&&
$(MAKE)
$(AM_MAKEFLAGS)
am--refresh
;;
\
*
)
\
*
)
\
echo
' 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__
maybe_remake_depfiles
)
;;
\
cd
$(top_builddir)
&&
$(SHELL)
./config.status
$(subdir)
/
$@
$(am__
depfiles_maybe
)
;;
\
esac
;
esac
;
$(top_srcdir)/build-aux/sgx_enclave.am $(am__empty)
:
$(top_srcdir)/build-aux/sgx_enclave.am $(am__empty)
:
...
@@ -441,28 +432,22 @@ mostlyclean-compile:
...
@@ -441,28 +432,22 @@ mostlyclean-compile:
distclean-compile
:
distclean-compile
:
-
rm
-f
*
.tab.c
-
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)/AESUtils.Po@am__quote@
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/BLSEnclave.Po@am__quote@
# am--include-marker
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/BLSEnclave.Po@am__quote@
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/DH_dkg.Po@am__quote@
# am--include-marker
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/DH_dkg.Po@am__quote@
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/DKGUtils.Po@am__quote@
# am--include-marker
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/DKGUtils.Po@am__quote@
@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_g1.Po@am__quote@
@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_g2.Po@am__quote@
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/alt_bn128_init.Po@am__quote@
# am--include-marker
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/alt_bn128_init.Po@am__quote@
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/curves.Po@am__quote@
# am--include-marker
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/curves.Po@am__quote@
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/domain_parameters.Po@am__quote@
# am--include-marker
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/domain_parameters.Po@am__quote@
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/numbertheory.Po@am__quote@
# am--include-marker
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/numbertheory.Po@am__quote@
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/point.Po@am__quote@
# am--include-marker
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/point.Po@am__quote@
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/secure_enclave.Po@am__quote@
# am--include-marker
@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@
# am--include-marker
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/secure_enclave_t.Po@am__quote@
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/signature.Po@am__quote@
# am--include-marker
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/signature.Po@am__quote@
@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_debug.Po@am__quote@
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/signed_enclave_rel.Po@am__quote@
# am--include-marker
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/signed_enclave_rel.Po@am__quote@
$(am__depfiles_remade)
:
@
$(MKDIR_P)
$
(
@D
)
@
echo
'# dummy'
>
$@
-t
&&
$(am__mv)
$@
-t
$@
am--depfiles
:
$(am__depfiles_remade)
.c.o
:
.c.o
:
@am__fastdepCC_TRUE@
$(AM_V_CC)$(COMPILE)
-MT
$@
-MD
-MP
-MF
$(DEPDIR)/$*.Tpo
-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)
...
@@ -586,10 +571,7 @@ cscopelist-am: $(am__tagged_files)
distclean-tags
:
distclean-tags
:
-
rm
-f
TAGS ID GTAGS GRTAGS GSYMS GPATH tags
-
rm
-f
TAGS ID GTAGS GRTAGS GSYMS GPATH tags
distdir
:
$(BUILT_SOURCES)
distdir
:
$(DISTFILES)
$(MAKE)
$(AM_MAKEFLAGS)
distdir-am
distdir-am
:
$(DISTFILES)
@
srcdirstrip
=
`
echo
"
$(srcdir)
"
|
sed
's/[].[^$$\\*]/\\\\&/g'
`
;
\
@
srcdirstrip
=
`
echo
"
$(srcdir)
"
|
sed
's/[].[^$$\\*]/\\\\&/g'
`
;
\
topsrcdirstrip
=
`
echo
"
$(top_srcdir)
"
|
sed
's/[].[^$$\\*]/\\\\&/g'
`
;
\
topsrcdirstrip
=
`
echo
"
$(top_srcdir)
"
|
sed
's/[].[^$$\\*]/\\\\&/g'
`
;
\
list
=
'
$(DISTFILES)
'
;
\
list
=
'
$(DISTFILES)
'
;
\
...
@@ -662,22 +644,7 @@ clean: clean-am
...
@@ -662,22 +644,7 @@ clean: clean-am
clean-am
:
clean-generic clean-libexecPROGRAMS mostlyclean-am
clean-am
:
clean-generic clean-libexecPROGRAMS mostlyclean-am
distclean
:
distclean-am
distclean
:
distclean-am
-
rm
-f
./
$(DEPDIR)
/AESUtils.Po
-
rm
-rf
./
$(DEPDIR)
-
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
-f
Makefile
-
rm
-f
Makefile
distclean-am
:
clean-am distclean-compile distclean-generic
\
distclean-am
:
clean-am distclean-compile distclean-generic
\
distclean-tags
distclean-tags
...
@@ -723,22 +690,7 @@ install-ps-am:
...
@@ -723,22 +690,7 @@ install-ps-am:
installcheck-am
:
installcheck-am
:
maintainer-clean
:
maintainer-clean-am
maintainer-clean
:
maintainer-clean-am
-
rm
-f
./
$(DEPDIR)
/AESUtils.Po
-
rm
-rf
./
$(DEPDIR)
-
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
-f
Makefile
-
rm
-f
Makefile
maintainer-clean-am
:
distclean-am maintainer-clean-generic
maintainer-clean-am
:
distclean-am maintainer-clean-generic
...
@@ -758,19 +710,19 @@ uninstall-am: uninstall-libexecPROGRAMS
...
@@ -758,19 +710,19 @@ uninstall-am: uninstall-libexecPROGRAMS
.MAKE
:
install-am install-strip
.MAKE
:
install-am install-strip
.PHONY
:
CTAGS GTAGS TAGS all all-am
am--depfiles check check-am clean
\
.PHONY
:
CTAGS GTAGS TAGS all all-am
check check-am clean clean-generic
\
clean-
generic clean-libexecPROGRAMS cscopelist-am ctags
\
clean-
libexecPROGRAMS cscopelist-am ctags ctags-am distclean
\
ctags-am distclean distclean-compile distclean-generic
\
distclean-compile distclean-generic distclean-tags distdir dvi
\
d
istclean-tags distdir dvi dvi-am html html-am info info
-am
\
d
vi-am html html-am info info-am install install
-am
\
install
install-am install-data install-data-am install-dvi
\
install
-data install-data-am install-dvi install-dvi-am
\
install-
dvi-am install-exec install-exec-am install-html
\
install-
exec install-exec-am install-html install-html-am
\
install-
html-am install-info install-info-am
\
install-
info install-info-am install-libexecPROGRAMS
\
install-
libexecPROGRAMS install-man install-pdf install-pdf-am
\
install-
man install-pdf install-pdf-am install-ps
\
install-ps
install-ps-am install-strip installcheck
\
install-ps
-am install-strip installcheck installcheck-am
\
install
check-am installdirs maintainer-clean
\
install
dirs maintainer-clean maintainer-clean-generic
\
m
aintainer-clean-generic mostlyclean mostlyclean-compile
\
m
ostlyclean mostlyclean-compile mostlyclean-generic pdf pdf-am
\
mostlyclean-generic pdf pdf-am ps ps-am tags tags-am uninstall
\
ps ps-am tags tags-am uninstall uninstall-am
\
uninstall-
am uninstall-
libexecPROGRAMS
uninstall-libexecPROGRAMS
.PRECIOUS
:
Makefile
.PRECIOUS
:
Makefile
...
...
sgxwallet.c
View file @
3074ad6a
...
@@ -73,11 +73,12 @@ int main(int argc, char *argv[]) {
...
@@ -73,11 +73,12 @@ int main(int argc, char *argv[]) {
switch
(
opt
)
{
switch
(
opt
)
{
case
'h'
:
case
'h'
:
if
(
strlen
(
argv
[
1
])
==
2
)
{
if
(
strlen
(
argv
[
1
])
==
2
)
{
fprintf
(
stderr
,
"-c
client certificate will not be checked
\n
"
);
fprintf
(
stderr
,
"-c
do not verify client certificate
\n
"
);
fprintf
(
stderr
,
"-s
client certificate will be signed automatically
\n
"
);
fprintf
(
stderr
,
"-s
sign client certificate without human confirmation
\n
"
);
fprintf
(
stderr
,
"-d turn on debug output
\n
"
);
fprintf
(
stderr
,
"-d turn on debug output
\n
"
);
fprintf
(
stderr
,
"-0 SGXWalletServer will be launched on http (not https)
\n
"
);
fprintf
(
stderr
,
"-0 launch SGXWalletServer using http (not https)
\n
"
);
fprintf
(
stderr
,
"-b Enter backup key
\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
);
exit
(
0
);
}
else
{
}
else
{
fprintf
(
stderr
,
"unknown flag %s
\n
"
,
argv
[
1
]);
fprintf
(
stderr
,
"unknown flag %s
\n
"
,
argv
[
1
]);
...
...
stubclient.h
View file @
3074ad6a
...
@@ -12,7 +12,7 @@ class StubClient : public jsonrpc::Client
...
@@ -12,7 +12,7 @@ class StubClient : public jsonrpc::Client
public
:
public
:
StubClient
(
jsonrpc
::
IClientConnector
&
conn
,
jsonrpc
::
clientVersion_t
type
=
jsonrpc
::
JSONRPC_CLIENT_V2
)
:
jsonrpc
::
Client
(
conn
,
type
)
{}
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
;
Json
::
Value
p
;
p
[
"index"
]
=
index
;
p
[
"index"
]
=
index
;
...
@@ -27,7 +27,7 @@ class StubClient : public jsonrpc::Client
...
@@ -27,7 +27,7 @@ class StubClient : public jsonrpc::Client
throw
jsonrpc
::
JsonRpcException
(
jsonrpc
::
Errors
::
ERROR_CLIENT_INVALID_RESPONSE
,
result
.
toStyledString
());
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
;
Json
::
Value
p
;
p
[
"keyShareName"
]
=
keyShareName
;
p
[
"keyShareName"
]
=
keyShareName
;
...
@@ -42,7 +42,7 @@ class StubClient : public jsonrpc::Client
...
@@ -42,7 +42,7 @@ class StubClient : public jsonrpc::Client
throw
jsonrpc
::
JsonRpcException
(
jsonrpc
::
Errors
::
ERROR_CLIENT_INVALID_RESPONSE
,
result
.
toStyledString
());
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
;
Json
::
Value
p
;
p
[
"key"
]
=
key
;
p
[
"key"
]
=
key
;
...
@@ -54,7 +54,7 @@ class StubClient : public jsonrpc::Client
...
@@ -54,7 +54,7 @@ class StubClient : public jsonrpc::Client
throw
jsonrpc
::
JsonRpcException
(
jsonrpc
::
Errors
::
ERROR_CLIENT_INVALID_RESPONSE
,
result
.
toStyledString
());
throw
jsonrpc
::
JsonRpcException
(
jsonrpc
::
Errors
::
ERROR_CLIENT_INVALID_RESPONSE
,
result
.
toStyledString
());
}
}
Json
::
Value
generateECDSAKey
()
throw
(
jsonrpc
::
JsonRpcException
)
Json
::
Value
generateECDSAKey
()
{
{
Json
::
Value
p
;
Json
::
Value
p
;
p
=
Json
::
nullValue
;
p
=
Json
::
nullValue
;
...
@@ -65,7 +65,7 @@ class StubClient : public jsonrpc::Client
...
@@ -65,7 +65,7 @@ class StubClient : public jsonrpc::Client
throw
jsonrpc
::
JsonRpcException
(
jsonrpc
::
Errors
::
ERROR_CLIENT_INVALID_RESPONSE
,
result
.
toStyledString
());
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
;
Json
::
Value
p
;
p
[
"keyName"
]
=
KeyName
;
p
[
"keyName"
]
=
KeyName
;
...
@@ -77,7 +77,7 @@ class StubClient : public jsonrpc::Client
...
@@ -77,7 +77,7 @@ class StubClient : public jsonrpc::Client
throw
jsonrpc
::
JsonRpcException
(
jsonrpc
::
Errors
::
ERROR_CLIENT_INVALID_RESPONSE
,
result
.
toStyledString
());
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
;
Json
::
Value
p
;
p
[
"keyName"
]
=
keyName
;
p
[
"keyName"
]
=
keyName
;
...
@@ -88,7 +88,7 @@ class StubClient : public jsonrpc::Client
...
@@ -88,7 +88,7 @@ class StubClient : public jsonrpc::Client
throw
jsonrpc
::
JsonRpcException
(
jsonrpc
::
Errors
::
ERROR_CLIENT_INVALID_RESPONSE
,
result
.
toStyledString
());
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
;
Json
::
Value
p
;
p
[
"base"
]
=
base
;
p
[
"base"
]
=
base
;
...
@@ -101,7 +101,7 @@ class StubClient : public jsonrpc::Client
...
@@ -101,7 +101,7 @@ class StubClient : public jsonrpc::Client
throw
jsonrpc
::
JsonRpcException
(
jsonrpc
::
Errors
::
ERROR_CLIENT_INVALID_RESPONSE
,
result
.
toStyledString
());
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
;
Json
::
Value
p
;
p
[
"polyName"
]
=
polyName
;
p
[
"polyName"
]
=
polyName
;
...
@@ -113,7 +113,7 @@ class StubClient : public jsonrpc::Client
...
@@ -113,7 +113,7 @@ class StubClient : public jsonrpc::Client
throw
jsonrpc
::
JsonRpcException
(
jsonrpc
::
Errors
::
ERROR_CLIENT_INVALID_RESPONSE
,
result
.
toStyledString
());
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
;
Json
::
Value
p
;
p
[
"polyName"
]
=
polyName
;
p
[
"polyName"
]
=
polyName
;
...
@@ -126,7 +126,7 @@ class StubClient : public jsonrpc::Client
...
@@ -126,7 +126,7 @@ class StubClient : public jsonrpc::Client
throw
jsonrpc
::
JsonRpcException
(
jsonrpc
::
Errors
::
ERROR_CLIENT_INVALID_RESPONSE
,
result
.
toStyledString
());
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
;
Json
::
Value
p
;
p
[
"polyName"
]
=
polyName
;
p
[
"polyName"
]
=
polyName
;
...
@@ -140,7 +140,7 @@ class StubClient : public jsonrpc::Client
...
@@ -140,7 +140,7 @@ class StubClient : public jsonrpc::Client
throw
jsonrpc
::
JsonRpcException
(
jsonrpc
::
Errors
::
ERROR_CLIENT_INVALID_RESPONSE
,
result
.
toStyledString
());
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
;
Json
::
Value
p
;
p
[
"ethKeyName"
]
=
ethKeyName
;
p
[
"ethKeyName"
]
=
ethKeyName
;
...
@@ -156,7 +156,7 @@ class StubClient : public jsonrpc::Client
...
@@ -156,7 +156,7 @@ class StubClient : public jsonrpc::Client
throw
jsonrpc
::
JsonRpcException
(
jsonrpc
::
Errors
::
ERROR_CLIENT_INVALID_RESPONSE
,
result
.
toStyledString
());
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
;
Json
::
Value
p
;
p
[
"blsKeyName"
]
=
blsKeyName
;
p
[
"blsKeyName"
]
=
blsKeyName
;
...
@@ -172,7 +172,7 @@ class StubClient : public jsonrpc::Client
...
@@ -172,7 +172,7 @@ class StubClient : public jsonrpc::Client
throw
jsonrpc
::
JsonRpcException
(
jsonrpc
::
Errors
::
ERROR_CLIENT_INVALID_RESPONSE
,
result
.
toStyledString
());
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
;
Json
::
Value
p
;
p
[
"blsKeyName"
]
=
blsKeyName
;
p
[
"blsKeyName"
]
=
blsKeyName
;
...
@@ -184,7 +184,7 @@ class StubClient : public jsonrpc::Client
...
@@ -184,7 +184,7 @@ class StubClient : public jsonrpc::Client
throw
jsonrpc
::
JsonRpcException
(
jsonrpc
::
Errors
::
ERROR_CLIENT_INVALID_RESPONSE
,
result
.
toStyledString
());
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
;
Json
::
Value
p
;
p
[
"polyName"
]
=
polyName
;
p
[
"polyName"
]
=
polyName
;
...
@@ -196,7 +196,7 @@ class StubClient : public jsonrpc::Client
...
@@ -196,7 +196,7 @@ class StubClient : public jsonrpc::Client
throw
jsonrpc
::
JsonRpcException
(
jsonrpc
::
Errors
::
ERROR_CLIENT_INVALID_RESPONSE
,
result
.
toStyledString
());
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
;
Json
::
Value
p
;
p
[
"x"
]
=
x
;
p
[
"x"
]
=
x
;
...
@@ -208,7 +208,7 @@ class StubClient : public jsonrpc::Client
...
@@ -208,7 +208,7 @@ class StubClient : public jsonrpc::Client
throw
jsonrpc
::
JsonRpcException
(
jsonrpc
::
Errors
::
ERROR_CLIENT_INVALID_RESPONSE
,
result
.
toStyledString
());
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
;
Json
::
Value
p
;
p
[
"polyName"
]
=
polyName
;
p
[
"polyName"
]
=
polyName
;
...
@@ -223,7 +223,7 @@ class StubClient : public jsonrpc::Client
...
@@ -223,7 +223,7 @@ class StubClient : public jsonrpc::Client
////CSRManagerServer
////CSRManagerServer
Json
::
Value
getUnsignedCSRs
()
throw
(
jsonrpc
::
JsonRpcException
)
Json
::
Value
getUnsignedCSRs
()
{
{
Json
::
Value
p
;
Json
::
Value
p
;
p
=
Json
::
nullValue
;
p
=
Json
::
nullValue
;
...
@@ -236,7 +236,7 @@ class StubClient : public jsonrpc::Client
...
@@ -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
;
Json
::
Value
p
;
p
[
"hash"
]
=
hash
;
p
[
"hash"
]
=
hash
;
...
@@ -249,7 +249,7 @@ class StubClient : public jsonrpc::Client
...
@@ -249,7 +249,7 @@ class StubClient : public jsonrpc::Client
}
}
Json
::
Value
getServerStatus
()
throw
(
jsonrpc
::
JsonRpcException
)
Json
::
Value
getServerStatus
()
{
{
Json
::
Value
p
;
Json
::
Value
p
;
p
=
Json
::
nullValue
;
p
=
Json
::
nullValue
;
...
...
tests.bash
0 → 100755
View file @
3074ad6a
#!/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]
testw.cpp
View file @
3074ad6a
...
@@ -34,19 +34,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
...
@@ -34,19 +34,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
*/
#include <libff/algebra/fields/fp.hpp>
#include <libff/algebra/fields/fp.hpp>
#include <dkg/dkg.h>
#include <dkg/dkg.h>
#include <jsonrpccpp/server/connectors/httpserver.h>
#include <jsonrpccpp/server/connectors/httpserver.h>
#include <libff/algebra/curves/alt_bn128/alt_bn128_pp.hpp>
#include <libff/algebra/curves/alt_bn128/alt_bn128_pp.hpp>
#include <libff/algebra/exponentiation/exponentiation.hpp>
#include <libff/algebra/exponentiation/exponentiation.hpp>
#include <libff/algebra/fields/fp.hpp>
#include <libff/algebra/fields/fp.hpp>
#include <dkg/dkg.h>
#include <dkg/dkg.h>
#include "sgxwallet_common.h"
#include "sgxwallet_common.h"
#include "create_enclave.h"
#include "create_enclave.h"
#include "secure_enclave_u.h"
#include "secure_enclave_u.h"
...
@@ -54,46 +46,36 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
...
@@ -54,46 +46,36 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <gmp.h>
#include <gmp.h>
#include <sgx_urts.h>
#include <sgx_urts.h>
#include <stdio.h>
#include <stdio.h>
#include "BLSCrypto.h"
#include "BLSCrypto.h"
#include "ServerInit.h"
#include "ServerInit.h"
#include "DKGCrypto.h"
#include "DKGCrypto.h"
#include "RPCException.h"
#include "RPCException.h"
#include "LevelDB.h"
#include "LevelDB.h"
#include "SGXWalletServer.hpp"
#include "SGXWalletServer.hpp"
#include <sgx_tcrypto.h>
#include <sgx_tcrypto.h>
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#include "catch.hpp"
#include "catch.hpp"
#include "stubclient.h"
#include "stubclient.h"
#include "BLSSigShare.h"
#include "BLSSigShare.h"
#include "BLSSigShareSet.h"
#include "BLSSigShareSet.h"
#include "BLSPublicKeyShare.h"
#include "BLSPublicKeyShare.h"
#include "BLSPublicKey.h"
#include "BLSPublicKey.h"
#include "SEKManager.h"
#include "SEKManager.h"
#include <thread>
#include <thread>
#include "common.h"
#include "common.h"
#include "stubclient.h"
#include <jsonrpccpp/client/connectors/httpclient.h>
default_random_engine
rand_gen
((
unsigned
int
)
time
(
0
));
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_t
t
;
mpz_init
(
t
);
mpz_init
(
t
);
el
.
as_bigint
().
to_mpz
(
t
);
el
.
as_bigint
().
to_mpz
(
t
);
char
arr
[
mpz_sizeinbase
(
t
,
10
)
+
2
];
char
arr
[
mpz_sizeinbase
(
t
,
10
)
+
2
];
char
*
tmp
=
mpz_get_str
(
arr
,
10
,
t
);
char
*
tmp
=
mpz_get_str
(
arr
,
10
,
t
);
mpz_clear
(
t
);
mpz_clear
(
t
);
...
@@ -115,25 +97,22 @@ int updated;
...
@@ -115,25 +97,22 @@ int updated;
#define TEST_BLS_KEY_NAME "SCHAIN:17:INDEX:5:KEY:1"
#define TEST_BLS_KEY_NAME "SCHAIN:17:INDEX:5:KEY:1"
void
reset_db
()
{
void
reset_db
()
{
//std::string db_name = SGXDATA_FOLDER + WALLETDB_NAME;
//string db_name = SGXDATA_FOLDER + WALLETDB_NAME;
REQUIRE
(
system
(
"rm -rf "
WALLETDB_NAME
)
==
0
);
REQUIRE
(
system
(
"rm -rf "
WALLETDB_NAME
)
==
0
);
}
}
char
*
encryptTestKey
()
{
char
*
encryptTestKey
()
{
const
char
*
key
=
TEST_BLS_KEY_SHARE
;
const
char
*
key
=
TEST_BLS_KEY_SHARE
;
int
errStatus
=
-
1
;
int
errStatus
=
-
1
;
vector
<
char
>
errMsg
(
BUF_LEN
,
0
);;
char
*
errMsg
=
(
char
*
)
calloc
(
BUF_LEN
,
1
);
char
*
encryptedKeyHex
=
encryptBLSKeyShare2Hex
(
&
errStatus
,
errMsg
.
data
(),
key
);
char
*
encryptedKeyHex
=
encryptBLSKeyShare2Hex
(
&
errStatus
,
errMsg
,
key
);
REQUIRE
(
encryptedKeyHex
!=
nullptr
);
REQUIRE
(
encryptedKeyHex
!=
nullptr
);
REQUIRE
(
errStatus
==
0
);
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 len %d
\n
"
,
(
int
)
strlen
(
encryptedKeyHex
));
printf
(
"Encrypted key %s
\n
"
,
encryptedKeyHex
);
printf
(
"Encrypted key %s
\n
"
,
encryptedKeyHex
);
...
@@ -142,13 +121,13 @@ char* encryptTestKey() {
...
@@ -142,13 +121,13 @@ char* encryptTestKey() {
TEST_CASE
(
"BLS key encrypt"
,
"[bls-key-encrypt]"
)
{
TEST_CASE
(
"BLS key encrypt"
,
"[bls-key-encrypt]"
)
{
DEBUG_PRINT
=
1
;
DEBUG_PRINT
=
1
;
is_sgx_https
=
0
;
is_sgx_https
=
0
;
init_all
(
false
,
false
,
init_SEK
);
autoconfirm
=
true
;
char
*
key
=
encryptTestKey
();
init_all
(
false
,
true
,
init_SEK
);
auto
key
=
encryptTestKey
();
REQUIRE
(
key
!=
nullptr
);
REQUIRE
(
key
!=
nullptr
);
free
(
key
);
}
}
...
@@ -157,210 +136,111 @@ TEST_CASE("BLS key encrypt/decrypt", "[bls-key-encrypt-decrypt]") {
...
@@ -157,210 +136,111 @@ TEST_CASE("BLS key encrypt/decrypt", "[bls-key-encrypt-decrypt]") {
DEBUG_PRINT
=
1
;
DEBUG_PRINT
=
1
;
is_sgx_https
=
0
;
is_sgx_https
=
0
;
autoconfirm
=
true
;
init_all
(
false
,
true
,
init_SEK
);
init_all
(
false
,
false
,
init_SEK
);
//init_enclave();
//init_enclave();
int
errStatus
=
-
1
;
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
);
REQUIRE
(
encryptedKey
!=
nullptr
);
char
*
plaintextKey
=
decryptBLSKeyShareFromHex
(
&
errStatus
,
errMsg
.
data
(),
encryptedKey
);
char
*
plaintextKey
=
decryptBLSKeyShareFromHex
(
&
errStatus
,
errMsg
,
encryptedKey
);
free
(
encryptedKey
);
REQUIRE
(
errStatus
==
0
);
REQUIRE
(
errStatus
==
0
);
REQUIRE
(
strcmp
(
plaintextKey
,
TEST_BLS_KEY_SHARE
)
==
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 len %d
\n
"
,
(
int
)
strlen
(
plaintextKey
));
printf
(
"Decrypted key: %s
\n
"
,
plaintextKey
);
printf
(
"Decrypted key: %s
\n
"
,
plaintextKey
);
free
(
plaintextKey
);
sgx_destroy_enclave
(
eid
);
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]"
)
{
autoconfirm
=
true
;
TEST_CASE
(
"DKG gen test"
,
"[dkg-gen]"
)
{
//init_all();
//init_all();
init_enclave
();
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
;
int
err_status
=
0
;
uint32_t
enc_len
=
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
);
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
);
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
;
uint32_t
dec_len
;
status
=
decrypt_dkg_secret
(
eid
,
&
err_status
,
errMsg1
,
encrypted_dkg_secret
,
(
uint8_t
*
)
secret
,
&
dec_len
);
status
=
decrypt_dkg_secret
(
eid
,
&
err_status
,
errMsg1
.
data
(),
encrypted_dkg_secret
.
data
(),
REQUIRE
(
status
==
SGX_SUCCESS
);
(
uint8_t
*
)
secret
.
data
(),
&
dec_len
);
printf
(
"
\n
decrypt_dkg_secret completed with status: %d %s
\n
"
,
err_status
,
errMsg1
);
REQUIRE
(
status
==
SGX_SUCCESS
);
printf
(
"decrypted secret %s
\n\n
"
,
secret
);
printf
(
"secret length %d
\n
"
,
strlen
(
secret
));
printf
(
"decr length %d
\n
"
,
dec_len
);
free
(
errMsg
);
printf
(
"
\n
decrypt_dkg_secret completed with status: %d %s
\n
"
,
err_status
,
errMsg1
.
data
()
);
free
(
errMsg1
);
printf
(
"decrypted secret %s
\n\n
"
,
secret
.
data
()
);
free
(
encrypted_dkg_secret
);
printf
(
"secret length %d
\n
"
,
(
int
)
strlen
(
secret
.
data
())
);
free
(
secret
);
printf
(
"decr length %d
\n
"
,
dec_len
);
sgx_destroy_enclave
(
eid
);
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
str
(
koefs
);
string
delim
;
string
delim
;
delim
.
push_back
(
symbol
);
delim
.
push_back
(
symbol
);
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
==
string
::
npos
)
pos
=
str
.
length
();
if
(
pos
==
string
::
npos
)
pos
=
str
.
length
();
string
token
=
str
.
substr
(
prev
,
pos
-
prev
);
string
token
=
str
.
substr
(
prev
,
pos
-
prev
);
if
(
!
token
.
empty
())
{
if
(
!
token
.
empty
())
{
libff
::
alt_bn128_Fr
koef
(
token
.
c_str
());
libff
::
alt_bn128_Fr
koef
(
token
.
c_str
());
tokens
.
push_back
(
koef
);
tokens
.
push_back
(
koef
);
}
}
prev
=
pos
+
delim
.
length
();
prev
=
pos
+
delim
.
length
();
}
}
while
(
pos
<
str
.
length
()
&&
prev
<
str
.
length
());
while
(
pos
<
str
.
length
()
&&
prev
<
str
.
length
());
return
tokens
;
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
();
libff
::
init_alt_bn128_params
();
string
str
(
koefs
);
string
str
(
koefs
);
string
delim
;
string
delim
;
delim
.
push_back
(
symbol
);
delim
.
push_back
(
symbol
);
vector
<
string
>
G2_strings
;
vector
<
string
>
G2_strings
;
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
==
string
::
npos
)
pos
=
str
.
length
();
if
(
pos
==
string
::
npos
)
pos
=
str
.
length
();
string
token
=
str
.
substr
(
prev
,
pos
-
prev
);
string
token
=
str
.
substr
(
prev
,
pos
-
prev
);
if
(
!
token
.
empty
())
{
if
(
!
token
.
empty
())
{
string
koef
(
token
.
c_str
());
string
koef
(
token
.
c_str
());
G2_strings
.
push_back
(
koef
);
G2_strings
.
push_back
(
koef
);
}
}
prev
=
pos
+
delim
.
length
();
prev
=
pos
+
delim
.
length
();
}
}
while
(
pos
<
str
.
length
()
&&
prev
<
str
.
length
());
while
(
pos
<
str
.
length
()
&&
prev
<
str
.
length
());
return
G2_strings
;
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
::
init_alt_bn128_params
();
libff
::
alt_bn128_G2
koef
=
libff
::
alt_bn128_G2
::
zero
();
libff
::
alt_bn128_G2
koef
=
libff
::
alt_bn128_G2
::
zero
();
koef
.
X
.
c0
=
libff
::
alt_bn128_Fq
(
G2_str_vect
.
at
(
0
).
c_str
());
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){
...
@@ -373,155 +253,146 @@ libff::alt_bn128_G2 VectStringToG2(const vector<string>& G2_str_vect){
return
koef
;
return
koef
;
}
}
TEST_CASE
(
"DKG public shares test"
,
"[dkg-pub_shares]"
)
{
TEST_CASE
(
"DKG public shares test"
,
"[dkg-pub_shares]"
)
{
autoconfirm
=
true
;
//init_all();
//init_all();
libff
::
init_alt_bn128_params
();
libff
::
init_alt_bn128_params
();
init_enclave
();
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
;
int
err_status
=
0
;
uint32_t
enc_len
=
0
;
uint32_t
enc_len
=
0
;
unsigned
t
=
32
,
n
=
32
;
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
);
REQUIRE
(
status
==
SGX_SUCCESS
);
//printf("gen_dkg_public completed with status: %d %s \n", err_status, errMsg);
//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
colon
=
':'
;
char
*
public_shares
=
(
char
*
)
calloc
(
10000
,
1
);
vector
<
char
>
public_shares
(
10000
,
0
);
status
=
get_public_shares
(
eid
,
&
err_status
,
errMsg1
,
encrypted_dkg_secret
,
enc_len
,
public_shares
,
t
,
n
);
status
=
get_public_shares
(
eid
,
&
err_status
,
errMsg1
.
data
(),
encrypted_dkg_secret
.
data
(),
enc_len
,
public_shares
.
data
(),
t
,
n
);
REQUIRE
(
status
==
SGX_SUCCESS
);
REQUIRE
(
status
==
SGX_SUCCESS
);
printf
(
"
\n
get_public_shares status: %d error %s
\n\n
"
,
err_status
,
errMsg1
);
printf
(
"
\n
get_public_shares status: %d error %s
\n\n
"
,
err_status
,
errMsg1
.
data
()
);
printf
(
" LEN: %d
\n
"
,
strlen
(
public_shares
));
printf
(
" LEN: %d
\n
"
,
(
int
)
strlen
(
public_shares
.
data
()
));
printf
(
" result: %s
\n
"
,
public_shares
);
printf
(
" result: %s
\n
"
,
public_shares
.
data
()
);
vector
<
string
>
G2_strings
=
SplitString
(
public_shares
,
','
);
vector
<
string
>
G2_strings
=
SplitString
(
public_shares
.
data
()
,
','
);
vector
<
libff
::
alt_bn128_G2
>
pub_shares_G2
;
vector
<
libff
::
alt_bn128_G2
>
pub_shares_G2
;
for
(
int
i
=
0
;
i
<
G2_strings
.
size
();
i
++
)
{
for
(
u_int64_t
i
=
0
;
i
<
G2_strings
.
size
();
i
++
)
{
vector
<
string
>
koef_str
=
SplitString
(
G2_strings
.
at
(
i
).
c_str
(),
':'
);
vector
<
string
>
koef_str
=
SplitString
(
G2_strings
.
at
(
i
).
c_str
(),
':'
);
libff
::
alt_bn128_G2
el
=
VectStringToG2
(
koef_str
);
//
libff::alt_bn128_G2 el = VectStringToG2(koef_str);
//cerr << "pub_share G2 " << i+1 << " : " << endl;
//cerr << "pub_share G2 " << i+1 << " : " << endl;
//el.print_coordinates();
//el.print_coordinates();
pub_shares_G2
.
push_back
(
VectStringToG2
(
koef_str
));
pub_shares_G2
.
push_back
(
VectStringToG2
(
koef_str
));
}
}
char
*
secret
=
(
char
*
)
calloc
(
DKG_MAX_SEALED_LEN
,
sizeof
(
char
));
vector
<
char
>
secret
(
DKG_MAX_SEALED_LEN
,
0
);
status
=
decrypt_dkg_secret
(
eid
,
&
err_status
,
errMsg1
,
encrypted_dkg_secret
,
(
uint8_t
*
)
secret
,
&
enc_len
);
status
=
decrypt_dkg_secret
(
eid
,
&
err_status
,
errMsg1
.
data
(),
encrypted_dkg_secret
.
data
(),
(
uint8_t
*
)
secret
.
data
(),
&
enc_len
);
REQUIRE
(
status
==
SGX_SUCCESS
);
REQUIRE
(
status
==
SGX_SUCCESS
);
printf
(
"
\n
decrypt_dkg_secret completed with status: %d %s
\n
"
,
err_status
,
errMsg1
);
printf
(
"
\n
decrypt_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_Fr
>
poly
=
SplitStringToFr
(
secret
.
data
()
,
colon
);
vector
<
libff
::
alt_bn128_G2
>
pub_shares_dkg
=
dkg_obj
.
VerificationVector
(
poly
);
vector
<
libff
::
alt_bn128_G2
>
pub_shares_dkg
=
dkg_obj
.
VerificationVector
(
poly
);
printf
(
"calculated public shares (X.c0):
\n
"
);
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
);
libff
::
alt_bn128_G2
el
=
pub_shares_dkg
.
at
(
i
);
el
.
to_affine_coordinates
();
el
.
to_affine_coordinates
();
libff
::
alt_bn128_Fq
x_c0_el
=
el
.
X
.
c0
;
libff
::
alt_bn128_Fq
x_c0_el
=
el
.
X
.
c0
;
mpz_t
x_c0
;
mpz_t
x_c0
;
mpz_init
(
x_c0
);
mpz_init
(
x_c0
);
x_c0_el
.
as_bigint
().
to_mpz
(
x_c0
);
x_c0_el
.
as_bigint
().
to_mpz
(
x_c0
);
char
arr
[
mpz_sizeinbase
(
x_c0
,
10
)
+
2
];
char
arr
[
mpz_sizeinbase
(
x_c0
,
10
)
+
2
];
char
*
share_str
=
mpz_get_str
(
arr
,
10
,
x_c0
);
char
*
share_str
=
mpz_get_str
(
arr
,
10
,
x_c0
);
printf
(
" %s
\n
"
,
share_str
);
printf
(
" %s
\n
"
,
share_str
);
mpz_clear
(
x_c0
);
mpz_clear
(
x_c0
);
}
}
bool
res
=
(
pub_shares_G2
==
pub_shares_dkg
);
bool
res
=
(
pub_shares_G2
==
pub_shares_dkg
);
REQUIRE
(
res
==
true
);
REQUIRE
(
res
==
true
);
free
(
errMsg
);
free
(
errMsg1
);
free
(
encrypted_dkg_secret
);
free
(
public_shares
);
sgx_destroy_enclave
(
eid
);
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_all();
init_enclave
();
init_enclave
();
uint8_t
*
encrypted_key
=
(
uint8_t
*
)
calloc
(
BUF_LEN
,
1
);
char
*
errMsg
=
(
char
*
)
calloc
(
1024
,
1
);
vector
<
char
>
errMsg
(
1024
,
1
);
char
*
result
=
(
char
*
)
calloc
(
130
,
1
);
vector
<
char
>
result
(
130
,
1
);
int
err_status
=
0
;
int
err_status
=
0
;
uint32_t
enc_len
=
0
;
uint32_t
enc_len
=
0
;
vector
<
uint8_t
>
encrypted_dkg_secret
(
DKG_MAX_SEALED_LEN
,
0
);
uint8_t
*
encrypted_dkg_secret
=
(
uint8_t
*
)
calloc
(
DKG_MAX_SEALED_LEN
,
1
);
status
=
gen_dkg_secret
(
eid
,
&
err_status
,
errMsg
.
data
(),
encrypted_dkg_secret
.
data
(),
&
enc_len
,
2
);
status
=
gen_dkg_secret
(
eid
,
&
err_status
,
errMsg
,
encrypted_dkg_secret
,
&
enc_len
,
2
);
REQUIRE
(
status
==
SGX_SUCCESS
);
REQUIRE
(
status
==
SGX_SUCCESS
);
cerr
<<
" poly generated"
<<
endl
;
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
);
REQUIRE
(
status
==
SGX_SUCCESS
);
cerr
<<
" poly set"
<<
endl
;
cerr
<<
" poly set"
<<
endl
;
uint8_t
*
encr_pr_DHkey
=
(
uint8_t
*
)
calloc
(
1024
,
1
);
vector
<
uint8_t
>
encrPRDHKey
(
1024
,
0
);
char
*
pub_key_x
=
(
char
*
)
calloc
(
1024
,
1
);
char
*
pub_key_y
=
(
char
*
)
calloc
(
1024
,
1
);
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
);
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
);
sgx_destroy_enclave
(
eid
);
}
}
TEST_CASE
(
"DKG verification test"
,
"[dkg-verify]"
)
{
TEST_CASE
(
"DKG verification test"
,
"[dkg-verify]"
)
{
autoconfirm
=
true
;
// init_all();
// init_all();
init_enclave
();
init_enclave
();
uint8_t
*
encrypted_key
=
(
uint8_t
*
)
calloc
(
BUF_LEN
,
1
);
char
*
errMsg
=
(
char
*
)
calloc
(
1024
,
1
);
vector
<
char
>
errMsg
(
1024
,
0
);
char
*
result
=
(
char
*
)
calloc
(
130
,
1
);
vector
<
char
>
result
(
130
,
0
);
int
err_status
=
0
;
int
err_status
=
0
;
uint32_t
enc_len
=
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
.
data
(),
encrypted_dkg_secret
.
data
(),
&
enc_len
,
2
);
status
=
gen_dkg_secret
(
eid
,
&
err_status
,
errMsg
,
encrypted_dkg_secret
,
&
enc_len
,
2
);
REQUIRE
(
status
==
SGX_SUCCESS
);
REQUIRE
(
status
==
SGX_SUCCESS
);
cerr
<<
" poly generated"
<<
endl
;
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
);
REQUIRE
(
status
==
SGX_SUCCESS
);
cerr
<<
" poly set"
<<
endl
;
cerr
<<
" poly set"
<<
endl
;
uint8_t
*
encr_pr_DHkey
=
(
uint8_t
*
)
calloc
(
1024
,
1
);
vector
<
uint8_t
>
encrPrDHKey
(
1024
,
0
);
char
*
pub_key_x
=
(
char
*
)
calloc
(
1024
,
1
);
char
*
pub_key_y
=
(
char
*
)
calloc
(
1024
,
1
);
char
*
pub_keyB
=
"c0152c48bf640449236036075d65898fded1e242c00acb45519ad5f788ea7cbf9a5df1559e7fc87932eee5478b1b9023de19df654395574a690843988c3ff475"
;
string
pub_keyB
=
"c0152c48bf640449236036075d65898fded1e242c00acb45519ad5f788ea7cbf9a5df1559e7fc87932eee5478b1b9023de19df654395574a690843988c3ff475"
;
char
s_shareG2
[
320
];
vector
<
char
>
s_shareG2
(
320
,
0
);
status
=
get_encr_sshare
(
eid
,
&
err_status
,
errMsg
,
encr_pr_DHkey
,
&
enc_len
,
result
,
s_shareG2
,
pub_keyB
,
2
,
2
,
1
);
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
);
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
);
sgx_destroy_enclave
(
eid
);
...
@@ -529,61 +400,63 @@ TEST_CASE( "DKG verification test", "[dkg-verify]" ) {
...
@@ -529,61 +400,63 @@ TEST_CASE( "DKG verification test", "[dkg-verify]" ) {
TEST_CASE
(
"ECDSA keygen and signature test"
,
"[ecdsa_test]"
)
{
TEST_CASE
(
"ECDSA keygen and signature test"
,
"[ecdsa_test]"
)
{
autoconfirm
=
true
;
init_enclave
();
init_enclave
();
char
*
errMsg
=
(
char
*
)
calloc
(
1024
,
1
);
vector
<
char
>
errMsg
(
1024
,
0
);
int
err_status
=
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
;
uint32_t
enc_len
=
0
;
//printf("before %p\n", pub_key_x);
//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
);
status
=
generate_ecdsa_key
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_pr_key
.
data
(),
&
enc_len
,
pub_key_x
.
data
(),
printf
(
"
\n
errMsg %s
\n
"
,
errMsg
);
pub_key_y
.
data
());
printf
(
"
\n
errMsg %s
\n
"
,
errMsg
.
data
());
REQUIRE
(
status
==
SGX_SUCCESS
);
REQUIRE
(
status
==
SGX_SUCCESS
);
printf
(
"
\n
was pub_key_x %s:
\n
"
,
pub_key_x
);
printf
(
"
\n
was pub_key_x %s:
\n
"
,
pub_key_x
.
data
()
);
printf
(
"
\n
was pub_key_y %s:
\n
"
,
pub_key_y
);
printf
(
"
\n
was pub_key_y %s:
\n
"
,
pub_key_y
.
data
()
);
/*printf("\nencr priv_key : \n");
/*printf("\nencr priv_key : \n");
for ( int i = 0; i < 1024 ; i++)
for ( int i = 0; i < 1024 ; i++)
printf("%u ", encr_pr_key[i]);*/
printf("%u ", encr_pr_key[i]);*/
char
*
hex
=
"3F891FDA3704F0368DAB65FA81EBE616F4AA2A0854995DA4DC0B59D2CADBD64F"
;
string
hex
=
"3F891FDA3704F0368DAB65FA81EBE616F4AA2A0854995DA4DC0B59D2CADBD64F"
;
// char* hex = "0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db";
// char* hex = "0x09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db";
printf
(
"hash length %d "
,
strlen
(
hex
));
printf
(
"hash length %d "
,
(
int
)
hex
.
size
(
));
char
*
signature_r
=
(
char
*
)
calloc
(
1024
,
1
);
vector
<
char
>
signature_r
(
1024
,
0
);
char
*
signature_s
=
(
char
*
)
calloc
(
1024
,
1
);
vector
<
char
>
signature_s
(
1024
,
0
);
uint8_t
signature_v
=
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
);
REQUIRE
(
status
==
SGX_SUCCESS
);
printf
(
"
\n
signature r : %s "
,
signature_r
);
printf
(
"
\n
signature r : %s "
,
signature_r
.
data
()
);
printf
(
"
\n
signature s: %s "
,
signature_s
);
printf
(
"
\n
signature s: %s "
,
signature_s
.
data
()
);
printf
(
"
\n
signature v: %u "
,
signature_v
);
printf
(
"
\n
signature v: %u "
,
signature_v
);
printf
(
"
\n
%s
\n
"
,
errMsg
);
printf
(
"
\n
%s
\n
"
,
errMsg
.
data
()
);
free
(
errMsg
);
sgx_destroy_enclave
(
eid
);
sgx_destroy_enclave
(
eid
);
printf
(
"the end of ecdsa test
\n
"
);
printf
(
"the end of ecdsa test
\n
"
);
}
}
TEST_CASE
(
"Test test"
,
"[test_test]"
)
{
TEST_CASE
(
"Test test"
,
"[test_test]"
)
{
autoconfirm
=
true
;
init_enclave
();
init_enclave
();
char
*
errMsg
=
(
char
*
)
calloc
(
1024
,
1
);
vector
<
char
>
errMsg
(
1024
,
0
);
int
err_status
=
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
);
char
*
pub_key_x
=
(
char
*
)
calloc
(
1024
,
1
);
vector
<
char
>
pub_key_y
(
1024
,
0
);
char
*
pub_key_y
=
(
char
*
)
calloc
(
1024
,
1
);
uint32_t
enc_len
=
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 );
//printf("\nerrMsg %s\n", errMsg );
REQUIRE
(
status
==
SGX_SUCCESS
);
REQUIRE
(
status
==
SGX_SUCCESS
);
...
@@ -595,50 +468,48 @@ TEST_CASE("Test test", "[test_test]") {
...
@@ -595,50 +468,48 @@ TEST_CASE("Test test", "[test_test]") {
//for ( int i = 0; i < 1024 ; i++)
//for ( int i = 0; i < 1024 ; i++)
// printf("%u ", encr_pr_key[i]);
// printf("%u ", encr_pr_key[i]);
//printf( "haha");
//free(errMsg);
sgx_destroy_enclave
(
eid
);
sgx_destroy_enclave
(
eid
);
}
}
TEST_CASE
(
"get public ECDSA key"
,
"[get_pub_ecdsa_key_test]"
)
{
TEST_CASE
(
"get public ECDSA key"
,
"[get_pub_ecdsa_key_test]"
)
{
autoconfirm
=
true
;
//init_all();
//init_all();
init_enclave
();
init_enclave
();
char
*
errMsg
=
(
char
*
)
calloc
(
1024
,
1
);
int
err_status
=
0
;
int
err_status
=
0
;
uint8_t
*
encr_pr_key
=
(
uint8_t
*
)
calloc
(
1024
,
1
);
vector
<
char
>
errMsg
(
1024
,
0
);
vector
<
uint8_t
>
encr_pr_key
(
1024
,
0
);
char
*
pub_key_x
=
(
char
*
)
calloc
(
1024
,
1
);
vector
<
char
>
pub_key_x
(
1024
,
0
);
char
*
pub_key_y
=
(
char
*
)
calloc
(
1024
,
1
);
vector
<
char
>
pub_key_y
(
1024
,
0
);
uint32_t
enc_len
=
0
;
uint32_t
enc_len
=
0
;
//printf("before %p\n", pub_key_x);
//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
);
status
=
generate_ecdsa_key
(
eid
,
&
err_status
,
errMsg
.
data
(),
encr_pr_key
.
data
(),
&
enc_len
,
pub_key_x
.
data
(),
printf
(
"
\n
errMsg %s
\n
"
,
errMsg
);
pub_key_y
.
data
());
printf
(
"
\n
errMsg %s
\n
"
,
errMsg
.
data
());
REQUIRE
(
status
==
SGX_SUCCESS
);
REQUIRE
(
status
==
SGX_SUCCESS
);
printf
(
"
\n
was pub_key_x %s length %d:
\n
"
,
pub_key_x
,
strlen
(
pub_key_x
));
printf
(
"
\n
was pub_key_x %s length %d:
\n
"
,
pub_key_x
.
data
(),
(
int
)
strlen
(
pub_key_x
.
data
()
));
printf
(
"
\n
was pub_key_y %s length %d:
\n
"
,
pub_key_y
,
strlen
(
pub_key_y
));
printf
(
"
\n
was pub_key_y %s length %d:
\n
"
,
pub_key_y
.
data
(),
(
int
)
strlen
(
pub_key_y
.
data
()
));
/*printf("\nencr priv_key %s: \n");
/*printf("\nencr priv_key %s: \n");
for ( int i = 0; i < 1024 ; i++)
for ( int i = 0; i < 1024 ; i++)
printf("%u ", encr_pr_key[i]);*/
printf("%u ", encr_pr_key[i]);*/
char
*
got_pub_key_x
=
(
char
*
)
calloc
(
1024
,
1
);
vector
<
char
>
got_pub_key_x
(
1024
,
0
);
char
*
got_pub_key_y
=
(
char
*
)
calloc
(
1024
,
1
);
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
);
REQUIRE
(
status
==
SGX_SUCCESS
);
printf
(
"
\n
now pub_key_x %s:
\n
"
,
got_pub_key_x
);
printf
(
"
\n
now pub_key_x %s:
\n
"
,
got_pub_key_x
.
data
());
printf
(
"
\n
now pub_key_y %s:
\n
"
,
got_pub_key_y
);
printf
(
"
\n
now pub_key_y %s:
\n
"
,
got_pub_key_y
.
data
());
printf
(
"
\n
pr key %s
\n
"
,
errMsg
);
printf
(
"
\n
pr key %s
\n
"
,
errMsg
.
data
());
free
(
errMsg
);
sgx_destroy_enclave
(
eid
);
sgx_destroy_enclave
(
eid
);
}
}
...
@@ -656,19 +527,18 @@ TEST_CASE("get public ECDSA key", "[get_pub_ecdsa_key_test]") {
...
@@ -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
jsonrpc
;
using
namespace
std
;
using
namespace
std
;
string
ConvertDecToHex
(
string
dec
,
int
numBytes
=
32
){
string
ConvertDecToHex
(
string
dec
,
int
numBytes
=
32
)
{
mpz_t
num
;
mpz_t
num
;
mpz_init
(
num
);
mpz_init
(
num
);
mpz_set_str
(
num
,
dec
.
c_str
(),
10
);
mpz_set_str
(
num
,
dec
.
c_str
(),
10
);
char
tmp
[
mpz_sizeinbase
(
num
,
16
)
+
2
]
;
vector
<
char
>
tmp
(
mpz_sizeinbase
(
num
,
16
)
+
2
,
0
)
;
char
*
hex
=
mpz_get_str
(
tmp
,
16
,
num
);
char
*
hex
=
mpz_get_str
(
tmp
.
data
()
,
16
,
num
);
string
result
=
hex
;
string
result
=
hex
;
int
n_zeroes
=
numBytes
*
2
-
result
.
length
();
int
n_zeroes
=
numBytes
*
2
-
result
.
length
();
...
@@ -681,8 +551,8 @@ string ConvertDecToHex(string dec, int numBytes = 32){
...
@@ -681,8 +551,8 @@ string ConvertDecToHex(string dec, int numBytes = 32){
TEST_CASE
(
"BLS_DKG test"
,
"[bls_dkg]"
)
{
TEST_CASE
(
"BLS_DKG test"
,
"[bls_dkg]"
)
{
is_sgx_https
=
0
;
is_sgx_https
=
0
;
DEBUG_PRINT
=
1
;
DEBUG_PRINT
=
1
;
cerr
<<
"test started"
<<
endl
;
cerr
<<
"test started"
<<
endl
;
init_all
(
false
,
fals
e
,
init_SEK
);
init_all
(
false
,
tru
e
,
init_SEK
);
cerr
<<
"Server inited"
<<
endl
;
cerr
<<
"Server inited"
<<
endl
;
HttpClient
client
(
"http://localhost:1029"
);
HttpClient
client
(
"http://localhost:1029"
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
...
@@ -703,9 +573,10 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") {
...
@@ -703,9 +573,10 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") {
int
schain_id
=
rand_gen
();
int
schain_id
=
rand_gen
();
int
dkg_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
();
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
);
c
.
generateDKGPoly
(
polyName
,
t
);
poly_names
[
i
]
=
polyName
;
poly_names
[
i
]
=
polyName
;
...
@@ -716,14 +587,14 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") {
...
@@ -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
);
secretShares
[
i
]
=
c
.
getSecretShare
(
poly_names
[
i
],
pubEthKeys
,
t
,
n
);
cout
<<
secretShares
[
i
]
<<
std
::
endl
;
cout
<<
secretShares
[
i
]
<<
endl
;
REQUIRE
(
secretShares
[
i
][
"status"
]
==
0
);
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
++
)
{
for
(
uint8_t
j
=
0
;
j
<
4
;
j
++
)
{
string
pubShare
=
VerifVects
[
i
][
"verificationVector"
][
k
][
j
].
asString
();
string
pubShare
=
VerifVects
[
i
][
"verificationVector"
][
k
][
j
].
asString
();
REQUIRE
(
pubShare
.
length
()
>
60
);
REQUIRE
(
pubShare
.
length
()
>
60
);
pubShares
[
i
]
+=
ConvertDecToHex
(
pubShare
);
pubShares
[
i
]
+=
ConvertDecToHex
(
pubShare
);
}
}
}
}
...
@@ -737,24 +608,26 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") {
...
@@ -737,24 +608,26 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") {
int
k
=
0
;
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
i
=
0
;
i
<
n
;
i
++
)
for
(
int
j
=
0
;
j
<
n
;
j
++
)
{
for
(
int
j
=
0
;
j
<
n
;
j
++
)
{
// if ( i != j ){
// if ( i != j ){
cerr
<<
"secretShare length is "
<<
secretShares
[
i
][
"secretShare"
].
asString
().
length
()
<<
endl
;
cerr
<<
"secretShare length is "
<<
secretShares
[
i
][
"secretShare"
].
asString
().
length
()
<<
endl
;
string
secretShare
=
secretShares
[
i
][
"secretShare"
].
asString
().
substr
(
192
*
j
,
192
);
string
secretShare
=
secretShares
[
i
][
"secretShare"
].
asString
().
substr
(
192
*
j
,
192
);
secShares_vect
[
i
]
+=
secretShares
[
j
][
"secretShare"
].
asString
().
substr
(
192
*
i
,
192
);
secShares_vect
[
i
]
+=
secretShares
[
j
][
"secretShare"
].
asString
().
substr
(
192
*
i
,
192
);
cerr
<<
"pubShare is "
<<
pubShares
[
i
]
<<
std
::
endl
;
cerr
<<
"pubShare is "
<<
pubShares
[
i
]
<<
endl
;
bool
res
=
c
.
dkgVerification
(
pubShares
[
i
],
EthKeys
[
j
][
"keyName"
].
asString
(),
secretShare
,
t
,
n
,
j
)[
"result"
].
asBool
();
bool
res
=
c
.
dkgVerification
(
pubShares
[
i
],
EthKeys
[
j
][
"keyName"
].
asString
(),
secretShare
,
t
,
n
,
j
)[
"result"
].
asBool
();
k
++
;
k
++
;
cerr
<<
"NOW K IS "
<<
k
<<
" i is "
<<
i
<<
" j is "
<<
j
<<
endl
;
cerr
<<
"NOW K IS "
<<
k
<<
" i is "
<<
i
<<
" j is "
<<
j
<<
endl
;
REQUIRE
(
res
);
REQUIRE
(
res
);
pSharesBad
[
i
][
0
]
=
'q'
;
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
();
res
=
wrongVerif
[
"result"
].
asBool
();
REQUIRE
(
!
res
);
REQUIRE
(
!
res
);
cerr
<<
"wrong verification "
<<
wrongVerif
<<
endl
;
cerr
<<
"wrong verification "
<<
wrongVerif
<<
endl
;
...
@@ -767,19 +640,20 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") {
...
@@ -767,19 +640,20 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") {
auto
hash_arr
=
make_shared
<
array
<
uint8_t
,
32
>>
();
auto
hash_arr
=
make_shared
<
array
<
uint8_t
,
32
>>
();
uint64_t
binLen
;
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"
);
throw
RPCException
(
INVALID_HEX
,
"Invalid hash"
);
}
}
map
<
size_t
,
shared_ptr
<
BLSPublicKeyShare
>>
koefs_pkeys_map
;
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
endName
=
poly_names
[
i
].
substr
(
4
);
string
blsName
=
"BLS_KEY"
+
poly_names
[
i
].
substr
(
4
);
string
blsName
=
"BLS_KEY"
+
poly_names
[
i
].
substr
(
4
);
string
secretShare
=
secretShares
[
i
][
"secretShare"
].
asString
();
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], 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
);
pubBLSKeys
[
i
]
=
c
.
getBLSPublicKeyShare
(
blsName
);
cerr
<<
"BLS KEY SHARE NAME IS "
<<
blsName
<<
endl
;
cerr
<<
"BLS KEY SHARE NAME IS "
<<
blsName
<<
endl
;
//string hash = "09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db";
//string hash = "09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db";
...
@@ -790,29 +664,29 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") {
...
@@ -790,29 +664,29 @@ TEST_CASE("BLS_DKG test", "[bls_dkg]") {
sigShareSet
.
addSigShare
(
make_shared
<
BLSSigShare
>
(
sig
));
sigShareSet
.
addSigShare
(
make_shared
<
BLSSigShare
>
(
sig
));
vector
<
string
>
pubKey_vect
;
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
());
pubKey_vect
.
push_back
(
pubBLSKeys
[
i
][
"blsPublicKeyShare"
][
j
].
asString
());
}
}
BLSPublicKeyShare
pubKey
(
make_shared
<
vector
<
string
>>
(
pubKey_vect
),
t
,
n
);
BLSPublicKeyShare
pubKey
(
make_shared
<
vector
<
string
>>
(
pubKey_vect
),
t
,
n
);
REQUIRE
(
pubKey
.
VerifySigWithHelper
(
hash_arr
,
make_shared
<
BLSSigShare
>
(
sig
)
,
t
,
n
));
REQUIRE
(
pubKey
.
VerifySigWithHelper
(
hash_arr
,
make_shared
<
BLSSigShare
>
(
sig
)
,
t
,
n
));
koefs_pkeys_map
[
i
+
1
]
=
make_shared
<
BLSPublicKeyShare
>
(
pubKey
);
koefs_pkeys_map
[
i
+
1
]
=
make_shared
<
BLSPublicKeyShare
>
(
pubKey
);
}
}
shared_ptr
<
BLSSignature
>
commonSig
=
sigShareSet
.
merge
();
shared_ptr
<
BLSSignature
>
commonSig
=
sigShareSet
.
merge
();
BLSPublicKey
common_public
(
make_shared
<
map
<
size_t
,
shared_ptr
<
BLSPublicKeyShare
>>>
(
koefs_pkeys_map
),
t
,
n
);
BLSPublicKey
common_public
(
make_shared
<
map
<
size_t
,
shared_ptr
<
BLSPublicKeyShare
>>>
(
koefs_pkeys_map
),
t
,
n
);
REQUIRE
(
common_public
.
VerifySigWithHelper
(
hash_arr
,
commonSig
,
t
,
n
)
);
REQUIRE
(
common_public
.
VerifySigWithHelper
(
hash_arr
,
commonSig
,
t
,
n
));
}
}
TEST_CASE
(
"API test"
,
"[api_test]"
)
{
TEST_CASE
(
"API test"
,
"[api_test]"
)
{
autoconfirm
=
true
;
//DEBUG_PRINT = 1;
//DEBUG_PRINT = 1;
is_sgx_https
=
0
;
is_sgx_https
=
0
;
//cerr << __GNUC__ << endl;
//cerr << __GNUC__ << endl;
cerr
<<
"API test started"
<<
endl
;
cerr
<<
"API test started"
<<
endl
;
init_all
(
false
,
fals
e
,
init_SEK
);
init_all
(
false
,
tru
e
,
init_SEK
);
//HttpServer httpserver(1025);
//HttpServer httpserver(1025);
//SGXWalletServer s(httpserver,
//SGXWalletServer s(httpserver,
// JSONRPC_SERVER_V2); // hybrid server (json-rpc 1.0 & 2.0)
// JSONRPC_SERVER_V2); // hybrid server (json-rpc 1.0 & 2.0)
...
@@ -836,7 +710,8 @@ TEST_CASE("API test", "[api_test]") {
...
@@ -836,7 +710,8 @@ TEST_CASE("API test", "[api_test]") {
Json
::
Value
genKey
=
c
.
generateECDSAKey
();
Json
::
Value
genKey
=
c
.
generateECDSAKey
();
cout
<<
genKey
<<
endl
;
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
());
Json
::
Value
getPubKey
=
c
.
getPublicECDSAKey
(
genKey
[
"keyName"
].
asString
());
cout
<<
getPubKey
<<
endl
;
cout
<<
getPubKey
<<
endl
;
// cout << c.renameESDSAKey("NODE_1CHAIN_1","tmp_NEK:bcacde0d26c0ea2c7e649992e7f791e1fba2492f5b7ae63dadb799075167c7fc");
// cout << c.renameESDSAKey("NODE_1CHAIN_1","tmp_NEK:bcacde0d26c0ea2c7e649992e7f791e1fba2492f5b7ae63dadb799075167c7fc");
...
@@ -860,8 +735,10 @@ TEST_CASE("API test", "[api_test]") {
...
@@ -860,8 +735,10 @@ TEST_CASE("API test", "[api_test]") {
// 2,2);
// 2,2);
Json
::
Value
publicKeys
;
Json
::
Value
publicKeys
;
publicKeys
.
append
(
"505f55a38f9c064da744f217d1cb993a17705e9839801958cda7c884e08ab4dad7fd8d22953d3ac7f0913de24fd67d7ed36741141b8a3da152d7ba954b0f14e2"
);
publicKeys
.
append
(
publicKeys
.
append
(
"378b3e6fdfe2633256ae1662fcd23466d02ead907b5d4366136341cea5e46f5a7bb67d897d6e35f619810238aa143c416f61c640ed214eb9c67a34c4a31b7d25"
);
"505f55a38f9c064da744f217d1cb993a17705e9839801958cda7c884e08ab4dad7fd8d22953d3ac7f0913de24fd67d7ed36741141b8a3da152d7ba954b0f14e2"
);
publicKeys
.
append
(
"378b3e6fdfe2633256ae1662fcd23466d02ead907b5d4366136341cea5e46f5a7bb67d897d6e35f619810238aa143c416f61c640ed214eb9c67a34c4a31b7d25"
);
// cout << c.getSecretShare("POLY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:1", publicKeys, 2, 2);
// cout << c.getSecretShare("POLY:SCHAIN_ID:1:NODE_ID:1:DKG_ID:1", publicKeys, 2, 2);
// cout << c.generateDKGPoly("p3", 3);
// cout << c.generateDKGPoly("p3", 3);
// cout << c.getSecretShare("p3",
// cout << c.getSecretShare("p3",
...
@@ -911,8 +788,9 @@ TEST_CASE("API test", "[api_test]") {
...
@@ -911,8 +788,9 @@ TEST_CASE("API test", "[api_test]") {
}
}
TEST_CASE
(
"getServerStatus test"
,
"[getServerStatus_test]"
)
{
TEST_CASE
(
"getServerStatus test"
,
"[getServerStatus_test]"
)
{
autoconfirm
=
true
;
is_sgx_https
=
0
;
is_sgx_https
=
0
;
init_all
(
false
,
false
,
init_SEK
);
init_all
(
false
,
true
,
init_SEK
);
HttpClient
client
(
"http://localhost:1029"
);
HttpClient
client
(
"http://localhost:1029"
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
REQUIRE
(
c
.
getServerStatus
()[
"status"
]
==
0
);
REQUIRE
(
c
.
getServerStatus
()[
"status"
]
==
0
);
...
@@ -920,8 +798,7 @@ TEST_CASE("getServerStatus test", "[getServerStatus_test]") {
...
@@ -920,8 +798,7 @@ TEST_CASE("getServerStatus test", "[getServerStatus_test]") {
}
}
void
SendRPCRequest
()
{
void
SendRPCRequest
(){
cout
<<
"Hello from thread "
<<
this_thread
::
get_id
()
<<
endl
;
cout
<<
"Hello from thread "
<<
this_thread
::
get_id
()
<<
endl
;
HttpClient
client
(
"http://localhost:1029"
);
HttpClient
client
(
"http://localhost:1029"
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
...
@@ -940,20 +817,21 @@ void SendRPCRequest(){
...
@@ -940,20 +817,21 @@ void SendRPCRequest(){
int
schain_id
=
rand_gen
();
int
schain_id
=
rand_gen
();
int
dkg_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
();
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
);
c
.
generateDKGPoly
(
polyName
,
t
);
poly_names
[
i
]
=
polyName
;
poly_names
[
i
]
=
polyName
;
VerifVects
[
i
]
=
c
.
getVerificationVector
(
polyName
,
t
,
n
);
VerifVects
[
i
]
=
c
.
getVerificationVector
(
polyName
,
t
,
n
);
REQUIRE
(
VerifVects
[
i
][
"status"
]
==
0
);
REQUIRE
(
VerifVects
[
i
][
"status"
]
==
0
);
cout
<<
"VV "
<<
i
<<
" "
<<
VerifVects
[
i
]
<<
endl
;
cout
<<
"VV "
<<
i
<<
" "
<<
VerifVects
[
i
]
<<
endl
;
pubEthKeys
.
append
(
EthKeys
[
i
][
"publicKey"
]);
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
);
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
++
)
{
for
(
uint8_t
j
=
0
;
j
<
4
;
j
++
)
{
string
pubShare
=
VerifVects
[
i
][
"Verification Vector"
][
k
][
j
].
asString
();
string
pubShare
=
VerifVects
[
i
][
"Verification Vector"
][
k
][
j
].
asString
();
pubShares
[
i
]
+=
ConvertDecToHex
(
pubShare
);
pubShares
[
i
]
+=
ConvertDecToHex
(
pubShare
);
...
@@ -966,17 +844,16 @@ void SendRPCRequest(){
...
@@ -966,17 +844,16 @@ void SendRPCRequest(){
int
k
=
0
;
int
k
=
0
;
vector
<
string
>
secShares_vect
(
n
);
vector
<
string
>
secShares_vect
(
n
);
for
(
int
i
=
0
;
i
<
n
;
i
++
)
for
(
int
i
=
0
;
i
<
n
;
i
++
)
for
(
int
j
=
0
;
j
<
n
;
j
++
)
{
for
(
int
j
=
0
;
j
<
n
;
j
++
)
{
// if ( i != j ){
// if ( i != j ){
cerr
<<
"SecretShare length is "
<<
secretShares
[
i
][
"secretShare"
].
asString
().
length
()
<<
endl
;
cerr
<<
"SecretShare length is "
<<
secretShares
[
i
][
"secretShare"
].
asString
().
length
()
<<
endl
;
string
secretShare
=
secretShares
[
i
][
"secretShare"
].
asString
().
substr
(
192
*
j
,
192
);
string
secretShare
=
secretShares
[
i
][
"secretShare"
].
asString
().
substr
(
192
*
j
,
192
);
secShares_vect
[
i
]
+=
secretShares
[
j
][
"secretShare"
].
asString
().
substr
(
192
*
i
,
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
);
Json
::
Value
verif
=
c
.
dkgVerification
(
pubShares
[
i
],
EthKeys
[
j
][
"keyName"
].
asString
(),
secretShare
,
t
,
n
,
j
);
cout
<<
verif
;
cout
<<
verif
;
bool
res
=
verif
[
"result"
].
asBool
();
k
++
;
k
++
;
cerr
<<
"NOW K IS "
<<
k
<<
" i is "
<<
i
<<
" j is "
<<
j
<<
endl
;
cerr
<<
"NOW K IS "
<<
k
<<
" i is "
<<
i
<<
" j is "
<<
j
<<
endl
;
// REQUIRE( res );
// REQUIRE( res );
...
@@ -984,26 +861,26 @@ void SendRPCRequest(){
...
@@ -984,26 +861,26 @@ void SendRPCRequest(){
}
}
BLSSigShareSet
sigShareSet
(
t
,
n
);
BLSSigShareSet
sigShareSet
(
t
,
n
);
string
hash
=
"09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db"
;
string
hash
=
"09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db"
;
auto
hash_arr
=
make_shared
<
array
<
uint8_t
,
32
>>
();
auto
hash_arr
=
make_shared
<
array
<
uint8_t
,
32
>>
();
uint64_t
binLen
;
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"
);
throw
RPCException
(
INVALID_HEX
,
"Invalid hash"
);
}
}
map
<
size_t
,
shared_ptr
<
BLSPublicKeyShare
>>
koefs_pkeys_map
;
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
endName
=
poly_names
[
i
].
substr
(
4
);
string
blsName
=
"BLS_KEY"
+
poly_names
[
i
].
substr
(
4
);
string
blsName
=
"BLS_KEY"
+
poly_names
[
i
].
substr
(
4
);
string
secretShare
=
secretShares
[
i
][
"secretShare"
].
asString
();
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], 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
);
pubBLSKeys
[
i
]
=
c
.
getBLSPublicKeyShare
(
blsName
);
cerr
<<
"BLS KEY SHARE NAME IS "
<<
blsName
<<
endl
;
cerr
<<
"BLS KEY SHARE NAME IS "
<<
blsName
<<
endl
;
string
hash
=
"09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db"
;
string
hash
=
"09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db"
;
...
@@ -1030,22 +907,23 @@ void SendRPCRequest(){
...
@@ -1030,22 +907,23 @@ void SendRPCRequest(){
// REQUIRE( common_public.VerifySigWithHelper(hash_arr, commonSig, t, n) );
// REQUIRE( common_public.VerifySigWithHelper(hash_arr, commonSig, t, n) );
}
}
TEST_CASE
(
"ManySimultaneousThreads"
,
"[many_threads_test]"
)
{
TEST_CASE
(
"ManySimultaneousThreads"
,
"[many_threads_test]"
)
{
autoconfirm
=
true
;
is_sgx_https
=
0
;
is_sgx_https
=
0
;
DEBUG_PRINT
=
1
;
DEBUG_PRINT
=
1
;
is_aes
=
1
;
is_aes
=
1
;
init_all
(
false
,
false
,
init_SEK
);
init_all
(
false
,
true
,
init_SEK
);
vector
<
thread
>
threads
;
vector
<
thread
>
threads
;
int
num_threads
=
4
;
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
));
threads
.
push_back
(
thread
(
SendRPCRequest
));
}
}
for
(
auto
&
thread
:
threads
)
{
for
(
auto
&
thread
:
threads
)
{
thread
.
join
();
thread
.
join
();
}
}
...
@@ -1053,12 +931,13 @@ TEST_CASE("ManySimultaneousThreads", "[many_threads_test]") {
...
@@ -1053,12 +931,13 @@ TEST_CASE("ManySimultaneousThreads", "[many_threads_test]") {
}
}
TEST_CASE
(
"ecdsa API test"
,
"[ecdsa_api_test]"
)
{
TEST_CASE
(
"ecdsa API test"
,
"[ecdsa_api_test]"
)
{
autoconfirm
=
true
;
DEBUG_PRINT
=
1
;
DEBUG_PRINT
=
1
;
is_sgx_https
=
0
;
is_sgx_https
=
0
;
is_aes
=
1
;
is_aes
=
1
;
cerr
<<
"ecdsa_api_test started"
<<
endl
;
cerr
<<
"ecdsa_api_test started"
<<
endl
;
init_all
(
false
,
fals
e
,
init_SEK
);
init_all
(
false
,
tru
e
,
init_SEK
);
cerr
<<
"Server inited"
<<
endl
;
cerr
<<
"Server inited"
<<
endl
;
HttpClient
client
(
"http://localhost:1029"
);
HttpClient
client
(
"http://localhost:1029"
);
...
@@ -1075,7 +954,8 @@ TEST_CASE("ecdsa API test", "[ecdsa_api_test]") {
...
@@ -1075,7 +954,8 @@ TEST_CASE("ecdsa API test", "[ecdsa_api_test]") {
REQUIRE
(
getPubKey
[
"status"
].
asInt
()
==
0
);
REQUIRE
(
getPubKey
[
"status"
].
asInt
()
==
0
);
REQUIRE
(
getPubKey
[
"publicKey"
].
asString
()
==
genKey
[
"publicKey"
].
asString
());
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
;
cout
<<
ecdsaSign
<<
endl
;
REQUIRE
(
ecdsaSign
[
"status"
].
asInt
()
==
0
);
REQUIRE
(
ecdsaSign
[
"status"
].
asInt
()
==
0
);
...
@@ -1103,11 +983,12 @@ TEST_CASE("ecdsa API test", "[ecdsa_api_test]") {
...
@@ -1103,11 +983,12 @@ TEST_CASE("ecdsa API test", "[ecdsa_api_test]") {
}
}
TEST_CASE
(
"dkg API test"
,
"[dkg_api_test]"
)
{
TEST_CASE
(
"dkg API test"
,
"[dkg_api_test]"
)
{
autoconfirm
=
true
;
DEBUG_PRINT
=
1
;
DEBUG_PRINT
=
1
;
is_sgx_https
=
0
;
is_sgx_https
=
0
;
cerr
<<
"dkg_api_test started"
<<
endl
;
cerr
<<
"dkg_api_test started"
<<
endl
;
init_all
(
false
,
fals
e
,
init_SEK
);
init_all
(
false
,
tru
e
,
init_SEK
);
cerr
<<
"Server inited"
<<
endl
;
cerr
<<
"Server inited"
<<
endl
;
HttpClient
client
(
"http://localhost:1029"
);
HttpClient
client
(
"http://localhost:1029"
);
...
@@ -1121,8 +1002,10 @@ TEST_CASE("dkg API test", "[dkg_api_test]") {
...
@@ -1121,8 +1002,10 @@ TEST_CASE("dkg API test", "[dkg_api_test]") {
Json
::
Value
genPoly
=
c
.
generateDKGPoly
(
polyName
,
2
);
Json
::
Value
genPoly
=
c
.
generateDKGPoly
(
polyName
,
2
);
Json
::
Value
publicKeys
;
Json
::
Value
publicKeys
;
publicKeys
.
append
(
"505f55a38f9c064da744f217d1cb993a17705e9839801958cda7c884e08ab4dad7fd8d22953d3ac7f0913de24fd67d7ed36741141b8a3da152d7ba954b0f14e2"
);
publicKeys
.
append
(
publicKeys
.
append
(
"378b3e6fdfe2633256ae1662fcd23466d02ead907b5d4366136341cea5e46f5a7bb67d897d6e35f619810238aa143c416f61c640ed214eb9c67a34c4a31b7d25"
);
"505f55a38f9c064da744f217d1cb993a17705e9839801958cda7c884e08ab4dad7fd8d22953d3ac7f0913de24fd67d7ed36741141b8a3da152d7ba954b0f14e2"
);
publicKeys
.
append
(
"378b3e6fdfe2633256ae1662fcd23466d02ead907b5d4366136341cea5e46f5a7bb67d897d6e35f619810238aa143c416f61c640ed214eb9c67a34c4a31b7d25"
);
// wrongName
// wrongName
Json
::
Value
genPolyWrongName
=
c
.
generateDKGPoly
(
"poly"
,
2
);
Json
::
Value
genPolyWrongName
=
c
.
generateDKGPoly
(
"poly"
,
2
);
...
@@ -1156,7 +1039,8 @@ TEST_CASE("dkg API test", "[dkg_api_test]") {
...
@@ -1156,7 +1039,8 @@ TEST_CASE("dkg API test", "[dkg_api_test]") {
cout
<<
verifVectWrong_n
<<
endl
;
cout
<<
verifVectWrong_n
<<
endl
;
Json
::
Value
publicKeys1
;
Json
::
Value
publicKeys1
;
publicKeys1
.
append
(
"505f55a38f9c064da744f217d1cb993a17705e9839801958cda7c884e08ab4dad7fd8d22953d3ac7f0913de24fd67d7ed36741141b8a3da152d7ba954b0f14e2"
);
publicKeys1
.
append
(
"505f55a38f9c064da744f217d1cb993a17705e9839801958cda7c884e08ab4dad7fd8d22953d3ac7f0913de24fd67d7ed36741141b8a3da152d7ba954b0f14e2"
);
Json
::
Value
secretSharesWrong_n
=
c
.
getSecretShare
(
polyName
,
publicKeys1
,
2
,
1
);
Json
::
Value
secretSharesWrong_n
=
c
.
getSecretShare
(
polyName
,
publicKeys1
,
2
,
1
);
REQUIRE
(
secretSharesWrong_n
[
"status"
].
asInt
()
!=
0
);
REQUIRE
(
secretSharesWrong_n
[
"status"
].
asInt
()
!=
0
);
cout
<<
secretSharesWrong_n
<<
endl
;
cout
<<
secretSharesWrong_n
<<
endl
;
...
@@ -1169,7 +1053,7 @@ TEST_CASE("dkg API test", "[dkg_api_test]") {
...
@@ -1169,7 +1053,7 @@ TEST_CASE("dkg API test", "[dkg_api_test]") {
//wrong verif
//wrong verif
Json
::
Value
Skeys
=
c
.
getSecretShare
(
polyName
,
publicKeys
,
2
,
2
);
Json
::
Value
Skeys
=
c
.
getSecretShare
(
polyName
,
publicKeys
,
2
,
2
);
Json
::
Value
verifVect
=
c
.
getVerificationVector
(
polyName
,
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
);
REQUIRE
(
verificationWrongSkeys
[
"status"
].
asInt
()
!=
0
);
cout
<<
verificationWrongSkeys
<<
endl
;
cout
<<
verificationWrongSkeys
<<
endl
;
...
@@ -1177,11 +1061,12 @@ TEST_CASE("dkg API test", "[dkg_api_test]") {
...
@@ -1177,11 +1061,12 @@ TEST_CASE("dkg API test", "[dkg_api_test]") {
}
}
TEST_CASE
(
"isPolyExists test"
,
"[is_poly_test]"
)
{
TEST_CASE
(
"isPolyExists test"
,
"[is_poly_test]"
)
{
autoconfirm
=
true
;
DEBUG_PRINT
=
1
;
DEBUG_PRINT
=
1
;
is_sgx_https
=
0
;
is_sgx_https
=
0
;
cerr
<<
"is_poly_test started"
<<
endl
;
cerr
<<
"is_poly_test started"
<<
endl
;
init_all
(
false
,
fals
e
,
init_SEK
);
init_all
(
false
,
tru
e
,
init_SEK
);
cerr
<<
"Server inited"
<<
endl
;
cerr
<<
"Server inited"
<<
endl
;
HttpClient
client
(
"http://localhost:1029"
);
HttpClient
client
(
"http://localhost:1029"
);
...
@@ -1205,15 +1090,15 @@ TEST_CASE("isPolyExists test", "[is_poly_test]") {
...
@@ -1205,15 +1090,15 @@ TEST_CASE("isPolyExists test", "[is_poly_test]") {
}
}
TEST_CASE
(
"AES_DKG test"
,
"[aes_dkg]"
)
{
TEST_CASE
(
"AES_DKG test"
,
"[aes_dkg]"
)
{
autoconfirm
=
true
;
is_sgx_https
=
0
;
is_sgx_https
=
0
;
DEBUG_PRINT
=
1
;
DEBUG_PRINT
=
1
;
is_aes
=
1
;
is_aes
=
1
;
reset_db
();
reset_db
();
std
::
cerr
<<
"test started"
<<
std
::
endl
;
cerr
<<
"test started"
<<
endl
;
init_all
(
false
,
fals
e
,
init_SEK
);
init_all
(
false
,
tru
e
,
init_SEK
);
cerr
<<
"Server inited"
<<
endl
;
cerr
<<
"Server inited"
<<
endl
;
HttpClient
client
(
"http://localhost:1029"
);
HttpClient
client
(
"http://localhost:1029"
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
...
@@ -1231,24 +1116,25 @@ TEST_CASE("AES_DKG test", "[aes_dkg]") {
...
@@ -1231,24 +1116,25 @@ TEST_CASE("AES_DKG test", "[aes_dkg]") {
int
schain_id
=
rand_gen
();
int
schain_id
=
rand_gen
();
int
dkg_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
();
EthKeys
[
i
]
=
c
.
generateECDSAKey
();
std
::
cerr
<<
"after gen key"
<<
std
::
endl
;
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
);
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
);
REQUIRE
(
EthKeys
[
i
][
"status"
]
==
0
);
cout
<<
c
.
generateDKGPoly
(
polyName
,
t
);
cout
<<
c
.
generateDKGPoly
(
polyName
,
t
);
poly_names
[
i
]
=
polyName
;
poly_names
[
i
]
=
polyName
;
VerifVects
[
i
]
=
c
.
getVerificationVector
(
polyName
,
t
,
n
);
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"
]);
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
);
secretShares
[
i
]
=
c
.
getSecretShare
(
poly_names
[
i
],
pubEthKeys
,
t
,
n
);
cout
<<
secretShares
[
i
]
<<
std
::
endl
;
cout
<<
secretShares
[
i
]
<<
endl
;
REQUIRE
(
secretShares
[
i
][
"status"
]
==
0
);
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
++
)
{
for
(
uint8_t
j
=
0
;
j
<
4
;
j
++
)
{
string
pubShare
=
VerifVects
[
i
][
"verificationVector"
][
k
][
j
].
asString
();
string
pubShare
=
VerifVects
[
i
][
"verificationVector"
][
k
][
j
].
asString
();
pubShares
[
i
]
+=
ConvertDecToHex
(
pubShare
);
pubShares
[
i
]
+=
ConvertDecToHex
(
pubShare
);
}
}
...
@@ -1262,20 +1148,20 @@ TEST_CASE("AES_DKG test", "[aes_dkg]") {
...
@@ -1262,20 +1148,20 @@ TEST_CASE("AES_DKG test", "[aes_dkg]") {
}
}
int
k
=
0
;
int
k
=
0
;
vector
<
string
>
secShares_vect
(
n
);
vector
<
string
>
secShares_vect
(
n
);
for
(
int
i
=
0
;
i
<
n
;
i
++
)
for
(
int
i
=
0
;
i
<
n
;
i
++
)
for
(
int
j
=
0
;
j
<
n
;
j
++
)
{
for
(
int
j
=
0
;
j
<
n
;
j
++
)
{
// if ( i != j ){
// if ( i != j ){
cerr
<<
"SecretShare length is "
<<
secretShares
[
i
][
"secretShare"
].
asString
().
length
()
<<
endl
;
cerr
<<
"SecretShare length is "
<<
secretShares
[
i
][
"secretShare"
].
asString
().
length
()
<<
endl
;
string
secretShare
=
secretShares
[
i
][
"secretShare"
].
asString
().
substr
(
192
*
j
,
192
);
string
secretShare
=
secretShares
[
i
][
"secretShare"
].
asString
().
substr
(
192
*
j
,
192
);
secShares_vect
[
i
]
+=
secretShares
[
j
][
"secretShare"
].
asString
().
substr
(
192
*
i
,
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
);
Json
::
Value
verif
=
c
.
dkgVerification
(
pubShares
[
i
],
EthKeys
[
j
][
"keyName"
].
asString
(),
secretShare
,
t
,
n
,
j
);
cout
<<
verif
;
cout
<<
verif
;
bool
res
=
verif
[
"result"
].
asBool
();
bool
res
=
verif
[
"result"
].
asBool
();
k
++
;
k
++
;
cerr
<<
"NOW K IS "
<<
k
<<
" i is "
<<
i
<<
" j is "
<<
j
<<
endl
;
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]") {
...
@@ -1292,56 +1178,57 @@ TEST_CASE("AES_DKG test", "[aes_dkg]") {
auto
hash_arr
=
make_shared
<
array
<
uint8_t
,
32
>>
();
auto
hash_arr
=
make_shared
<
array
<
uint8_t
,
32
>>
();
uint64_t
binLen
;
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"
);
throw
RPCException
(
INVALID_HEX
,
"Invalid hash"
);
}
}
map
<
size_t
,
shared_ptr
<
BLSPublicKeyShare
>>
koefs_pkeys_map
;
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
endName
=
poly_names
[
i
].
substr
(
4
);
string
blsName
=
"BLS_KEY"
+
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
);
pubBLSKeys
[
i
]
=
c
.
getBLSPublicKeyShare
(
blsName
);
cout
<<
pubBLSKeys
[
i
]
<<
endl
;
cout
<<
pubBLSKeys
[
i
]
<<
endl
;
REQUIRE
(
pubBLSKeys
[
i
][
"status"
]
==
0
);
REQUIRE
(
pubBLSKeys
[
i
][
"status"
]
==
0
);
cerr
<<
"BLS KEY SHARE NAME IS"
<<
blsName
<<
endl
;
cerr
<<
"BLS KEY SHARE NAME IS"
<<
blsName
<<
endl
;
string
hash
=
"09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db"
;
string
hash
=
"09c6137b97cdf159b9950f1492ee059d1e2b10eaf7d51f3a97d61f2eee2e81db"
;
BLSSigShares
[
i
]
=
c
.
blsSignMessageHash
(
blsName
,
hash
,
t
,
n
,
i
+
1
);
BLSSigShares
[
i
]
=
c
.
blsSignMessageHash
(
blsName
,
hash
,
t
,
n
,
i
+
1
);
cout
<<
BLSSigShares
[
i
]
<<
std
::
endl
;
cout
<<
BLSSigShares
[
i
]
<<
endl
;
REQUIRE
(
BLSSigShares
[
i
][
"status"
]
==
0
);
REQUIRE
(
BLSSigShares
[
i
][
"status"
]
==
0
);
cerr
<<
i
<<
" sig share is created "
<<
endl
;
cerr
<<
i
<<
" sig share is created "
<<
endl
;
shared_ptr
<
string
>
sig_share_ptr
=
make_shared
<
string
>
(
BLSSigShares
[
i
][
"signatureShare"
].
asString
());
shared_ptr
<
string
>
sig_share_ptr
=
make_shared
<
string
>
(
BLSSigShares
[
i
][
"signatureShare"
].
asString
());
BLSSigShare
sig
(
sig_share_ptr
,
i
+
1
,
t
,
n
);
BLSSigShare
sig
(
sig_share_ptr
,
i
+
1
,
t
,
n
);
sigShareSet
.
addSigShare
(
make_shared
<
BLSSigShare
>
(
sig
));
sigShareSet
.
addSigShare
(
make_shared
<
BLSSigShare
>
(
sig
));
vector
<
string
>
pubKey_vect
;
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
());
pubKey_vect
.
push_back
(
pubBLSKeys
[
i
][
"blsPublicKeyShare"
][
j
].
asString
());
}
}
BLSPublicKeyShare
pubKey
(
make_shared
<
vector
<
string
>>
(
pubKey_vect
),
t
,
n
);
BLSPublicKeyShare
pubKey
(
make_shared
<
vector
<
string
>>
(
pubKey_vect
),
t
,
n
);
REQUIRE
(
pubKey
.
VerifySigWithHelper
(
hash_arr
,
make_shared
<
BLSSigShare
>
(
sig
)
,
t
,
n
));
REQUIRE
(
pubKey
.
VerifySigWithHelper
(
hash_arr
,
make_shared
<
BLSSigShare
>
(
sig
)
,
t
,
n
));
koefs_pkeys_map
[
i
+
1
]
=
make_shared
<
BLSPublicKeyShare
>
(
pubKey
);
koefs_pkeys_map
[
i
+
1
]
=
make_shared
<
BLSPublicKeyShare
>
(
pubKey
);
}
}
shared_ptr
<
BLSSignature
>
commonSig
=
sigShareSet
.
merge
();
shared_ptr
<
BLSSignature
>
commonSig
=
sigShareSet
.
merge
();
BLSPublicKey
common_public
(
make_shared
<
map
<
size_t
,
shared_ptr
<
BLSPublicKeyShare
>>>
(
koefs_pkeys_map
),
t
,
n
);
BLSPublicKey
common_public
(
make_shared
<
map
<
size_t
,
shared_ptr
<
BLSPublicKeyShare
>>>
(
koefs_pkeys_map
),
t
,
n
);
REQUIRE
(
common_public
.
VerifySigWithHelper
(
hash_arr
,
commonSig
,
t
,
n
)
);
REQUIRE
(
common_public
.
VerifySigWithHelper
(
hash_arr
,
commonSig
,
t
,
n
)
);
sgx_destroy_enclave
(
eid
);
sgx_destroy_enclave
(
eid
);
}
}
TEST_CASE
(
"bls_sign_api test"
,
"[bls_sign]"
)
{
TEST_CASE
(
"bls_sign_api test"
,
"[bls_sign]"
)
{
autoconfirm
=
true
;
is_sgx_https
=
0
;
is_sgx_https
=
0
;
DEBUG_PRINT
=
1
;
DEBUG_PRINT
=
1
;
is_aes
=
1
;
is_aes
=
1
;
std
::
cerr
<<
"test started"
<<
std
::
endl
;
cerr
<<
"test started"
<<
endl
;
init_all
(
false
,
fals
e
,
init_SEK
);
init_all
(
false
,
tru
e
,
init_SEK
);
cerr
<<
"Server inited"
<<
endl
;
cerr
<<
"Server inited"
<<
endl
;
HttpClient
client
(
"http://localhost:1029"
);
HttpClient
client
(
"http://localhost:1029"
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
...
@@ -1355,7 +1242,6 @@ TEST_CASE("bls_sign_api test", "[bls_sign]") {
...
@@ -1355,7 +1242,6 @@ TEST_CASE("bls_sign_api test", "[bls_sign]") {
cout
<<
pubBLSKey
<<
endl
;
cout
<<
pubBLSKey
<<
endl
;
Json
::
Value
sign
=
c
.
blsSignMessageHash
(
blsName
,
hash
,
t
,
n
,
1
);
Json
::
Value
sign
=
c
.
blsSignMessageHash
(
blsName
,
hash
,
t
,
n
,
1
);
cout
<<
sign
<<
endl
;
cout
<<
sign
<<
endl
;
REQUIRE
(
sign
[
"status"
]
==
0
);
REQUIRE
(
sign
[
"status"
]
==
0
);
...
@@ -1371,38 +1257,126 @@ TEST_CASE("bls_sign_api test", "[bls_sign]") {
...
@@ -1371,38 +1257,126 @@ TEST_CASE("bls_sign_api test", "[bls_sign]") {
TEST_CASE
(
"AES encrypt/decrypt"
,
"[AES-encrypt-decrypt]"
)
{
TEST_CASE
(
"AES encrypt/decrypt"
,
"[AES-encrypt-decrypt]"
)
{
{
{
autoconfirm
=
true
;
DEBUG_PRINT
=
1
;
DEBUG_PRINT
=
1
;
is_sgx_https
=
0
;
is_sgx_https
=
0
;
init_all
(
false
,
fals
e
,
init_SEK
);
init_all
(
false
,
tru
e
,
init_SEK
);
//init_enclave();
//init_enclave();
int
errStatus
=
-
1
;
int
errStatus
=
-
1
;
char
*
errMsg
=
(
char
*
)
calloc
(
BUF_LEN
,
1
)
;
vector
<
char
>
errMsg
(
BUF_LEN
,
0
);
;
uint32_t
enc_len
;
uint32_t
enc_len
;
string
key
=
"123456789"
;
vector
<
uint8_t
>
encrypted_key
(
BUF_LEN
,
0
);
std
::
string
key
=
"123456789"
;
status
=
encrypt_key_aes
(
eid
,
&
errStatus
,
errMsg
.
data
(),
key
.
c_str
(),
encrypted_key
.
data
(),
&
enc_len
);
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
);
REQUIRE
(
status
==
0
);
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
];
vector
<
char
>
decr_key
(
BUF_LEN
,
0
);
memset
(
decr_key
,
0
,
BUF_LEN
);
status
=
decrypt_key_aes
(
eid
,
&
errStatus
,
errMsg
.
data
(),
encrypted_key
.
data
(),
enc_len
,
decr_key
.
data
());
status
=
decrypt_key_aes
(
eid
,
&
errStatus
,
errMsg
,
encrypted_key
,
enc_len
,
decr_key
);
REQUIRE
(
status
==
0
);
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
;
std
::
cerr
<<
"decrypted key is "
<<
decr_key
<<
std
::
endl
;
cerr
<<
"decrypted key is "
<<
decr_key
.
data
()
<<
endl
;
REQUIRE
(
key
.
compare
(
decr_key
)
==
0
);
REQUIRE
(
key
.
compare
(
decr_key
.
data
())
==
0
);
sgx_destroy_enclave
(
eid
);
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
//}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment