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
6f45b506
Unverified
Commit
6f45b506
authored
Jun 10, 2021
by
Oleh Nikolaiev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-3951 add more tests
parent
ab08ff9d
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
161 additions
and
13 deletions
+161
-13
testw.cpp
testw.cpp
+150
-0
testw.py
testw.py
+2
-1
RspMessage.h
zmq_src/RspMessage.h
+4
-0
ServerWorker.cpp
zmq_src/ServerWorker.cpp
+1
-2
ZMQClient.cpp
zmq_src/ZMQClient.cpp
+3
-2
ZMQClient.h
zmq_src/ZMQClient.h
+1
-1
ZMQServer.cpp
zmq_src/ZMQServer.cpp
+0
-7
No files found.
testw.cpp
View file @
6f45b506
...
@@ -946,6 +946,156 @@ TEST_CASE_METHOD(TestFixture, "AES_DKG V2 test", "[aes-dkg-v2]") {
...
@@ -946,6 +946,156 @@ TEST_CASE_METHOD(TestFixture, "AES_DKG V2 test", "[aes-dkg-v2]") {
REQUIRE
(
common_public
.
VerifySigWithHelper
(
hash_arr
,
commonSig
,
t
,
n
));
REQUIRE
(
common_public
.
VerifySigWithHelper
(
hash_arr
,
commonSig
,
t
,
n
));
}
}
TEST_CASE_METHOD
(
TestFixture
,
"AES_DKG V2 ZMQ test"
,
"[aes-dkg-v2-zmq]"
)
{
auto
client
=
make_shared
<
ZMQClient
>
(
ZMQ_IP
,
ZMQ_PORT
,
true
,
"./sgx_data/cert_data/rootCA.pem"
,
"./sgx_data/cert_data/rootCA.key"
);
int
n
=
2
,
t
=
2
;
vector
<
string
>
ethKeys
(
n
);
Json
::
Value
verifVects
[
n
];
Json
::
Value
pubEthKeys
;
vector
<
string
>
secretShares
(
n
);
Json
::
Value
pubBLSKeys
[
n
];
vector
<
string
>
blsSigShares
(
n
);
vector
<
string
>
pubShares
(
n
);
vector
<
string
>
polyNames
(
n
);
int
schainID
=
TestUtils
::
randGen
();
int
dkgID
=
TestUtils
::
randGen
();
for
(
uint8_t
i
=
0
;
i
<
n
;
i
++
)
{
auto
generatedKey
=
client
->
generateECDSAKey
();
ethKeys
[
i
]
=
generatedKey
.
second
;
string
polyName
=
"POLY:SCHAIN_ID:"
+
to_string
(
schainID
)
+
":NODE_ID:"
+
to_string
(
i
)
+
":DKG_ID:"
+
to_string
(
dkgID
);
CHECK_STATE
(
client
->
generateDKGPoly
(
polyName
,
t
));
polyNames
[
i
]
=
polyName
;
verifVects
[
i
]
=
client
->
getVerificationVector
(
polyName
,
t
);
pubEthKeys
.
append
(
generatedKey
.
first
);
}
for
(
uint8_t
i
=
0
;
i
<
n
;
i
++
)
{
secretShares
[
i
]
=
client
->
getSecretShare
(
polyNames
[
i
],
pubEthKeys
,
t
,
n
);
for
(
uint8_t
k
=
0
;
k
<
t
;
k
++
)
{
for
(
uint8_t
j
=
0
;
j
<
4
;
j
++
)
{
string
pubShare
=
verifVects
[
i
][
k
][
j
].
asString
();
pubShares
[
i
]
+=
TestUtils
::
convertDecToHex
(
pubShare
);
}
}
}
int
k
=
0
;
vector
<
string
>
secShares
(
n
);
for
(
int
i
=
0
;
i
<
n
;
i
++
)
for
(
int
j
=
0
;
j
<
n
;
j
++
)
{
string
secretShare
=
secretShares
[
i
].
substr
(
192
*
j
,
192
);
secShares
[
i
]
+=
secretShares
[
j
].
substr
(
192
*
i
,
192
);
REQUIRE
(
client
->
dkgVerification
(
pubShares
[
i
],
ethKeys
[
j
],
secretShare
,
t
,
n
,
j
));
k
++
;
}
auto
complaintResponse
=
client
->
complaintResponse
(
polyNames
[
1
],
t
,
n
,
0
);
string
dhKey
=
std
::
get
<
0
>
(
complaintResponse
);
string
shareG2
=
std
::
get
<
1
>
(
complaintResponse
);
string
secretShare
=
secretShares
[
1
].
substr
(
0
,
192
);
vector
<
char
>
message
(
65
,
0
);
SAFE_CHAR_BUF
(
encr_sshare
,
BUF_LEN
)
strncpy
(
encr_sshare
,
pubEthKeys
[
0
].
asString
().
c_str
(),
128
);
SAFE_CHAR_BUF
(
common_key
,
BUF_LEN
);
REQUIRE
(
sessionKeyRecoverDH
(
dhKey
.
c_str
(),
encr_sshare
,
common_key
)
==
0
);
uint8_t
key_to_hash
[
33
];
uint64_t
len
;
REQUIRE
(
hex2carray
(
common_key
,
&
len
,
key_to_hash
,
64
)
);
auto
hashed_key
=
cryptlite
::
sha256
::
hash_hex
(
string
((
char
*
)
key_to_hash
,
32
));
SAFE_CHAR_BUF
(
derived_key
,
33
)
uint64_t
key_length
;
REQUIRE
(
hex2carray
(
&
hashed_key
[
0
],
&
key_length
,
(
uint8_t
*
)
derived_key
,
33
));
SAFE_CHAR_BUF
(
encr_sshare_check
,
BUF_LEN
)
strncpy
(
encr_sshare_check
,
secretShare
.
c_str
(),
ECDSA_SKEY_LEN
-
1
);
REQUIRE
(
xorDecryptDHV2
(
derived_key
,
encr_sshare_check
,
message
)
==
0
);
mpz_t
hex_share
;
mpz_init
(
hex_share
);
mpz_set_str
(
hex_share
,
message
.
data
(),
16
);
libff
::
alt_bn128_Fr
share
(
hex_share
);
libff
::
alt_bn128_G2
decrypted_share_G2
=
share
*
libff
::
alt_bn128_G2
::
one
();
decrypted_share_G2
.
to_affine_coordinates
();
mpz_clear
(
hex_share
);
REQUIRE
(
convertG2ToString
(
decrypted_share_G2
)
==
shareG2
);
Json
::
Value
verificationVectorMult
=
std
::
get
<
2
>
(
complaintResponse
);
libff
::
alt_bn128_G2
verificationValue
=
libff
::
alt_bn128_G2
::
zero
();
for
(
int
i
=
0
;
i
<
t
;
++
i
)
{
libff
::
alt_bn128_G2
value
;
value
.
Z
=
libff
::
alt_bn128_Fq2
::
one
();
value
.
X
.
c0
=
libff
::
alt_bn128_Fq
(
verificationVectorMult
[
i
][
0
].
asCString
());
value
.
X
.
c1
=
libff
::
alt_bn128_Fq
(
verificationVectorMult
[
i
][
1
].
asCString
());
value
.
Y
.
c0
=
libff
::
alt_bn128_Fq
(
verificationVectorMult
[
i
][
2
].
asCString
());
value
.
Y
.
c1
=
libff
::
alt_bn128_Fq
(
verificationVectorMult
[
i
][
3
].
asCString
());
verificationValue
=
verificationValue
+
value
;
}
verificationValue
.
to_affine_coordinates
();
REQUIRE
(
verificationValue
==
decrypted_share_G2
);
BLSSigShareSet
sigShareSet
(
t
,
n
);
string
hash
=
SAMPLE_HASH
;
auto
hash_arr
=
make_shared
<
array
<
uint8_t
,
32
>
>
();
uint64_t
binLen
;
if
(
!
hex2carray
(
hash
.
c_str
(),
&
binLen
,
hash_arr
->
data
(),
32
))
{
throw
SGXException
(
TEST_INVALID_HEX
,
"Invalid hash"
);
}
map
<
size_t
,
shared_ptr
<
BLSPublicKeyShare
>>
coeffs_pkeys_map
;
for
(
int
i
=
0
;
i
<
t
;
i
++
)
{
string
blsName
=
"BLS_KEY"
+
polyNames
[
i
].
substr
(
4
);
REQUIRE
(
client
->
createBLSPrivateKey
(
blsName
,
ethKeys
[
i
],
polyNames
[
i
],
secShares
[
i
],
t
,
n
));
pubBLSKeys
[
i
]
=
client
->
getBLSPublicKey
(
blsName
);
string
hash
=
SAMPLE_HASH
;
blsSigShares
[
i
]
=
client
->
blsSignMessageHash
(
blsName
,
hash
,
t
,
n
);
REQUIRE
(
blsSigShares
[
i
].
length
()
>
0
);
shared_ptr
<
string
>
sig_share_ptr
=
make_shared
<
string
>
(
blsSigShares
[
i
]);
BLSSigShare
sig
(
sig_share_ptr
,
i
+
1
,
t
,
n
);
sigShareSet
.
addSigShare
(
make_shared
<
BLSSigShare
>
(
sig
));
vector
<
string
>
pubKey_vect
;
for
(
uint8_t
j
=
0
;
j
<
4
;
j
++
)
{
pubKey_vect
.
push_back
(
pubBLSKeys
[
i
][
j
].
asString
());
}
BLSPublicKeyShare
pubKey
(
make_shared
<
vector
<
string
>>
(
pubKey_vect
),
t
,
n
);
REQUIRE
(
pubKey
.
VerifySigWithHelper
(
hash_arr
,
make_shared
<
BLSSigShare
>
(
sig
),
t
,
n
));
coeffs_pkeys_map
[
i
+
1
]
=
make_shared
<
BLSPublicKeyShare
>
(
pubKey
);
}
shared_ptr
<
BLSSignature
>
commonSig
=
sigShareSet
.
merge
();
BLSPublicKey
common_public
(
make_shared
<
map
<
size_t
,
shared_ptr
<
BLSPublicKeyShare
>>>
(
coeffs_pkeys_map
),
t
,
n
);
REQUIRE
(
common_public
.
VerifySigWithHelper
(
hash_arr
,
commonSig
,
t
,
n
));
}
TEST_CASE_METHOD
(
TestFixture
,
"AES encrypt/decrypt"
,
"[aes-encrypt-decrypt]"
)
{
TEST_CASE_METHOD
(
TestFixture
,
"AES encrypt/decrypt"
,
"[aes-encrypt-decrypt]"
)
{
int
errStatus
=
0
;
int
errStatus
=
0
;
vector
<
char
>
errMsg
(
BUF_LEN
,
0
);
vector
<
char
>
errMsg
(
BUF_LEN
,
0
);
...
...
testw.py
View file @
6f45b506
...
@@ -62,7 +62,8 @@ testList = [ "[zmq-ecdsa]",
...
@@ -62,7 +62,8 @@ testList = [ "[zmq-ecdsa]",
"[dkg-poly-exists-zmq]"
,
"[dkg-poly-exists-zmq]"
,
"[dkg-aes-pub-shares]"
,
"[dkg-aes-pub-shares]"
,
"[aes-encrypt-decrypt]"
,
"[aes-encrypt-decrypt]"
,
"[aes-dkg-v2]"
"[aes-dkg-v2]"
,
"[aes-dkg-v2-zmq]"
]
]
...
...
zmq_src/RspMessage.h
View file @
6f45b506
...
@@ -185,6 +185,10 @@ public:
...
@@ -185,6 +185,10 @@ public:
string
getShare
()
{
string
getShare
()
{
return
getStringRapid
(
"share*G2"
);
return
getStringRapid
(
"share*G2"
);
}
}
Json
::
Value
getVerificationVectorMult
()
{
return
getJsonValueRapid
(
"verificationVectorMult"
);
}
};
};
...
...
zmq_src/ServerWorker.cpp
View file @
6f45b506
...
@@ -39,8 +39,7 @@ std::atomic <uint64_t> ServerWorker::workerCount(1);
...
@@ -39,8 +39,7 @@ std::atomic <uint64_t> ServerWorker::workerCount(1);
ServerWorker
::
ServerWorker
(
zmq
::
context_t
&
_ctx
,
int
sock_type
,
bool
_checkSignature
,
ServerWorker
::
ServerWorker
(
zmq
::
context_t
&
_ctx
,
int
sock_type
,
bool
_checkSignature
,
const
string
&
_caCert
)
:
checkSignature
(
_checkSignature
),
const
string
&
_caCert
)
:
checkSignature
(
_checkSignature
),
caCert
(
_caCert
),
caCert
(
_caCert
),
isExitRequested
(
false
)
{
isExitRequested
(
false
)
{
worker
=
make_shared
<
zmq
::
socket_t
>
(
_ctx
,
sock_type
);
worker
=
make_shared
<
zmq
::
socket_t
>
(
_ctx
,
sock_type
);
...
...
zmq_src/ZMQClient.cpp
View file @
6f45b506
...
@@ -440,16 +440,17 @@ Json::Value ZMQClient::getAllBlsPublicKeys(const Json::Value& publicShares, int
...
@@ -440,16 +440,17 @@ Json::Value ZMQClient::getAllBlsPublicKeys(const Json::Value& publicShares, int
return
result
->
getPublicKeys
();
return
result
->
getPublicKeys
();
}
}
pair
<
string
,
string
>
ZMQClient
::
complaintResponse
(
const
string
&
polyName
,
int
t
,
int
n
,
int
idx
)
{
tuple
<
string
,
string
,
Json
::
Value
>
ZMQClient
::
complaintResponse
(
const
string
&
polyName
,
int
t
,
int
n
,
int
idx
)
{
Json
::
Value
p
;
Json
::
Value
p
;
p
[
"type"
]
=
ZMQMessage
::
COMPLAINT_RESPONSE_REQ
;
p
[
"type"
]
=
ZMQMessage
::
COMPLAINT_RESPONSE_REQ
;
p
[
"polyName"
]
=
polyName
;
p
[
"polyName"
]
=
polyName
;
p
[
"t"
]
=
t
;
p
[
"t"
]
=
t
;
p
[
"n"
]
=
n
;
p
[
"n"
]
=
n
;
p
[
"ind"
]
=
idx
;
auto
result
=
dynamic_pointer_cast
<
complaintResponseRspMessage
>
(
doRequestReply
(
p
));
auto
result
=
dynamic_pointer_cast
<
complaintResponseRspMessage
>
(
doRequestReply
(
p
));
CHECK_STATE
(
result
);
CHECK_STATE
(
result
);
CHECK_STATE
(
result
->
getStatus
()
==
0
);
CHECK_STATE
(
result
->
getStatus
()
==
0
);
return
{
result
->
getDHKey
(),
result
->
getShare
()};
return
{
result
->
getDHKey
(),
result
->
getShare
()
,
result
->
getVerificationVectorMult
()
};
}
}
Json
::
Value
ZMQClient
::
multG2
(
const
string
&
x
)
{
Json
::
Value
ZMQClient
::
multG2
(
const
string
&
x
)
{
...
...
zmq_src/ZMQClient.h
View file @
6f45b506
...
@@ -111,7 +111,7 @@ public:
...
@@ -111,7 +111,7 @@ public:
Json
::
Value
getAllBlsPublicKeys
(
const
Json
::
Value
&
publicShares
,
int
n
,
int
t
);
Json
::
Value
getAllBlsPublicKeys
(
const
Json
::
Value
&
publicShares
,
int
n
,
int
t
);
pair
<
string
,
string
>
complaintResponse
(
const
string
&
polyName
,
int
t
,
int
n
,
int
idx
);
tuple
<
string
,
string
,
Json
::
Value
>
complaintResponse
(
const
string
&
polyName
,
int
t
,
int
n
,
int
idx
);
Json
::
Value
multG2
(
const
string
&
x
);
Json
::
Value
multG2
(
const
string
&
x
);
...
...
zmq_src/ZMQServer.cpp
View file @
6f45b506
...
@@ -41,14 +41,11 @@ ZMQServer::ZMQServer(bool _checkSignature, const string &_caCertFile)
...
@@ -41,14 +41,11 @@ ZMQServer::ZMQServer(bool _checkSignature, const string &_caCertFile)
:
checkSignature
(
_checkSignature
),
:
checkSignature
(
_checkSignature
),
caCertFile
(
_caCertFile
),
ctx_
(
make_shared
<
zmq
::
context_t
>
(
1
))
{
caCertFile
(
_caCertFile
),
ctx_
(
make_shared
<
zmq
::
context_t
>
(
1
))
{
frontend
=
make_shared
<
zmq
::
socket_t
>
(
*
ctx_
,
ZMQ_ROUTER
);
frontend
=
make_shared
<
zmq
::
socket_t
>
(
*
ctx_
,
ZMQ_ROUTER
);
backend
=
make_shared
<
zmq
::
socket_t
>
(
*
ctx_
,
ZMQ_DEALER
);
backend
=
make_shared
<
zmq
::
socket_t
>
(
*
ctx_
,
ZMQ_DEALER
);
//workerThreads = 2 * thread::hardware_concurrency();
//workerThreads = 2 * thread::hardware_concurrency();
workerThreads
=
1
;
// do one thread for now
workerThreads
=
1
;
// do one thread for now
if
(
_checkSignature
)
{
if
(
_checkSignature
)
{
...
@@ -61,13 +58,11 @@ ZMQServer::ZMQServer(bool _checkSignature, const string &_caCertFile)
...
@@ -61,13 +58,11 @@ ZMQServer::ZMQServer(bool _checkSignature, const string &_caCertFile)
int
linger
=
0
;
int
linger
=
0
;
zmq_setsockopt
(
*
frontend
,
ZMQ_LINGER
,
&
linger
,
sizeof
(
linger
));
zmq_setsockopt
(
*
frontend
,
ZMQ_LINGER
,
&
linger
,
sizeof
(
linger
));
zmq_setsockopt
(
*
backend
,
ZMQ_LINGER
,
&
linger
,
sizeof
(
linger
));
zmq_setsockopt
(
*
backend
,
ZMQ_LINGER
,
&
linger
,
sizeof
(
linger
));
}
}
void
ZMQServer
::
run
()
{
void
ZMQServer
::
run
()
{
auto
port
=
BASE_PORT
+
5
;
auto
port
=
BASE_PORT
+
5
;
...
@@ -92,7 +87,6 @@ void ZMQServer::run() {
...
@@ -92,7 +87,6 @@ void ZMQServer::run() {
throw
SGXException
(
ZMQ_COULD_NOT_BIND_BACK_END
,
"Could not bind to zmq backend."
);
throw
SGXException
(
ZMQ_COULD_NOT_BIND_BACK_END
,
"Could not bind to zmq backend."
);
}
}
spdlog
::
info
(
"Creating {} zmq server workers ..."
,
workerThreads
);
spdlog
::
info
(
"Creating {} zmq server workers ..."
,
workerThreads
);
try
{
try
{
...
@@ -131,7 +125,6 @@ void ZMQServer::run() {
...
@@ -131,7 +125,6 @@ void ZMQServer::run() {
}
}
}
}
void
ZMQServer
::
exitAll
()
{
void
ZMQServer
::
exitAll
()
{
spdlog
::
info
(
"Exiting zmq server workers ..."
);
spdlog
::
info
(
"Exiting zmq server workers ..."
);
...
...
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