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
9b090a3a
Unverified
Commit
9b090a3a
authored
Aug 01, 2021
by
Oleh Nikolaiev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-4411 add new function to zmq server
parent
63f34987
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
90 additions
and
10 deletions
+90
-10
testw.cpp
testw.cpp
+30
-5
testw.py
testw.py
+2
-1
ReqMessage.cpp
zmq_src/ReqMessage.cpp
+8
-0
ReqMessage.h
zmq_src/ReqMessage.h
+7
-0
RspMessage.cpp
zmq_src/RspMessage.cpp
+4
-0
RspMessage.h
zmq_src/RspMessage.h
+12
-0
ZMQClient.cpp
zmq_src/ZMQClient.cpp
+11
-0
ZMQClient.h
zmq_src/ZMQClient.h
+2
-0
ZMQMessage.cpp
zmq_src/ZMQMessage.cpp
+10
-2
ZMQMessage.h
zmq_src/ZMQMessage.h
+4
-2
No files found.
testw.cpp
View file @
9b090a3a
...
...
@@ -1184,15 +1184,12 @@ TEST_CASE_METHOD(TestFixtureNoReset, "Second run", "[second-run]") {
}
TEST_CASE_METHOD
(
TestFixture
,
"Test decryption share for threshold encryption"
,
"[te-decryption-share]"
)
{
// auto client = make_shared<ZMQClient>(ZMQ_IP, ZMQ_PORT, true, "./sgx_data/cert_data/rootCA.pem",
// "./sgx_data/cert_data/rootCA.key");
HttpClient
client
(
RPC_ENDPOINT
);
StubClient
c
(
client
,
JSONRPC_CLIENT_V2
);
std
::
string
key_str
=
"0xe632f7fde2c90a073ec43eaa90dca7b82476bf28815450a11191484934b9c3f"
;
std
::
string
name
=
"BLS_KEY:SCHAIN_ID:123456789:NODE_ID:0:DKG_ID:0"
;
auto
response
=
c
.
importBLSKeyShare
(
key_str
,
name
);
c
.
importBLSKeyShare
(
key_str
,
name
);
// the same key writtn in decimal
libff
::
alt_bn128_Fr
key
=
libff
::
alt_bn128_Fr
(
...
...
@@ -1215,8 +1212,36 @@ TEST_CASE_METHOD(TestFixture, "Test decryption share for threshold encryption",
REQUIRE
(
share
==
key
*
decryption_value
);
}
TEST_CASE_METHOD
(
TestFixtureZMQSign
,
"ZMQ-ecdsa"
,
"[zmq-ecdsa]"
)
{
TEST_CASE_METHOD
(
TestFixture
,
"Test decryption share for threshold encryption via zmq"
,
"[te-decryption-share-zmq]"
)
{
auto
client
=
make_shared
<
ZMQClient
>
(
ZMQ_IP
,
ZMQ_PORT
,
true
,
"./sgx_data/cert_data/rootCA.pem"
,
"./sgx_data/cert_data/rootCA.key"
);
std
::
string
key_str
=
"0xe632f7fde2c90a073ec43eaa90dca7b82476bf28815450a11191484934b9c3f"
;
std
::
string
name
=
"BLS_KEY:SCHAIN_ID:123456789:NODE_ID:0:DKG_ID:0"
;
client
->
importBLSKeyShare
(
key_str
,
name
);
// the same key writtn in decimal
libff
::
alt_bn128_Fr
key
=
libff
::
alt_bn128_Fr
(
"6507625568967977077291849236396320012317305261598035438182864059942098934847"
);
libff
::
alt_bn128_G2
decryption_value
=
libff
::
alt_bn128_G2
::
random_element
();
decryption_value
.
to_affine_coordinates
();
auto
decrytion_value_str
=
convertG2ToString
(
decryption_value
,
':'
);
auto
decryption_share
=
client
->
getDecryptionShare
(
name
,
decrytion_value_str
);
libff
::
alt_bn128_G2
share
;
share
.
Z
=
libff
::
alt_bn128_Fq2
::
one
();
share
.
X
.
c0
=
libff
::
alt_bn128_Fq
(
decryption_share
[
0
].
asCString
()
);
share
.
X
.
c1
=
libff
::
alt_bn128_Fq
(
decryption_share
[
1
].
asCString
()
);
share
.
Y
.
c0
=
libff
::
alt_bn128_Fq
(
decryption_share
[
2
].
asCString
()
);
share
.
Y
.
c1
=
libff
::
alt_bn128_Fq
(
decryption_share
[
3
].
asCString
()
);
REQUIRE
(
share
==
key
*
decryption_value
);
}
TEST_CASE_METHOD
(
TestFixtureZMQSign
,
"ZMQ-ecdsa"
,
"[zmq-ecdsa]"
)
{
HttpClient
htp
(
RPC_ENDPOINT
);
StubClient
c
(
htp
,
JSONRPC_CLIENT_V2
);
...
...
testw.py
View file @
9b090a3a
...
...
@@ -63,7 +63,8 @@ testList = [ "[zmq-ecdsa]",
"[aes-encrypt-decrypt]"
,
"[aes-dkg-v2]"
,
"[aes-dkg-v2-zmq]"
,
"[te-decryption-share]"
"[te-decryption-share]"
,
"[te-decryption-share-zmq]"
]
...
...
zmq_src/ReqMessage.cpp
View file @
9b090a3a
...
...
@@ -183,3 +183,11 @@ Json::Value deleteBLSKeyReqMessage::process() {
result
[
"type"
]
=
ZMQMessage
::
DELETE_BLS_KEY_RSP
;
return
result
;
}
Json
::
Value
GetDecryptionShareReqMessage
::
process
()
{
auto
blsKeyName
=
getStringRapid
(
"blsKeyName"
);
auto
publicDecryptionValue
=
getStringRapid
(
"publicDecryptionValue"
);
auto
result
=
SGXWalletServer
::
getDecryptionShareImpl
(
blsKeyName
,
publicDecryptionValue
);
result
[
"type"
]
=
ZMQMessage
::
GET_DECRYPTION_SHARE_RSP
;
return
result
;
}
zmq_src/ReqMessage.h
View file @
9b090a3a
...
...
@@ -178,4 +178,11 @@ public:
virtual
Json
::
Value
process
();
};
class
GetDecryptionShareReqMessage
:
public
ZMQMessage
{
public
:
GetDecryptionShareReqMessage
(
shared_ptr
<
rapidjson
::
Document
>&
_d
)
:
ZMQMessage
(
_d
)
{};
virtual
Json
::
Value
process
();
};
#endif //SGXWALLET_REQMESSAGE_H
zmq_src/RspMessage.cpp
View file @
9b090a3a
...
...
@@ -110,3 +110,7 @@ Json::Value getServerVersionRspMessage::process() {
Json
::
Value
deleteBLSKeyRspMessage
::
process
()
{
assert
(
false
);
}
Json
::
Value
GetDecryptionShareRspMessage
::
process
()
{
assert
(
false
);
}
zmq_src/RspMessage.h
View file @
9b090a3a
...
...
@@ -248,4 +248,16 @@ public:
};
class
GetDecryptionShareRspMessage
:
public
ZMQMessage
{
public
:
GetDecryptionShareRspMessage
(
shared_ptr
<
rapidjson
::
Document
>&
_d
)
:
ZMQMessage
(
_d
)
{};
virtual
Json
::
Value
process
();
Json
::
Value
getShare
()
{
return
getJsonValueRapid
(
"decryptionShare"
);
}
};
#endif //SGXWALLET_RSPMESSAGE_H
zmq_src/ZMQClient.cpp
View file @
9b090a3a
...
...
@@ -496,6 +496,17 @@ bool ZMQClient::deleteBLSKey(const string& blsKeyName) {
return
result
->
isSuccessful
();
}
Json
::
Value
ZMQClient
::
getDecryptionShare
(
const
string
&
blsKeyName
,
const
string
&
publicDecryptionValue
)
{
Json
::
Value
p
;
p
[
"type"
]
=
ZMQMessage
::
GET_DECRYPTION_SHARE_REQ
;
p
[
"blsKeyName"
]
=
blsKeyName
;
p
[
"publicDecryptionValue"
]
=
publicDecryptionValue
;
auto
result
=
dynamic_pointer_cast
<
GetDecryptionShareRspMessage
>
(
doRequestReply
(
p
));
CHECK_STATE
(
result
);
CHECK_STATE
(
result
->
getStatus
()
==
0
);
return
result
->
getShare
();
}
uint64_t
ZMQClient
::
getProcessID
()
{
return
syscall
(
__NR_gettid
);
}
zmq_src/ZMQClient.h
View file @
9b090a3a
...
...
@@ -122,6 +122,8 @@ public:
string
getServerVersion
();
bool
deleteBLSKey
(
const
string
&
blsKeyName
);
Json
::
Value
getDecryptionShare
(
const
string
&
blsKeyName
,
const
string
&
publicDecryptionValue
);
};
...
...
zmq_src/ZMQMessage.cpp
View file @
9b090a3a
...
...
@@ -227,6 +227,9 @@ shared_ptr <ZMQMessage> ZMQMessage::buildRequest(string &_type, shared_ptr <rapi
case
ENUM_DELETE_BLS_KEY_REQ
:
ret
=
make_shared
<
deleteBLSKeyReqMessage
>
(
_d
);
break
;
case
ENUM_GET_DECRYPTION_SHARE_REQ
:
ret
=
make_shared
<
GetDecryptionShareReqMessage
>
(
_d
);
break
;
default
:
break
;
}
...
...
@@ -305,6 +308,9 @@ shared_ptr <ZMQMessage> ZMQMessage::buildResponse(string &_type, shared_ptr <rap
case
ENUM_DELETE_BLS_KEY_RSP
:
ret
=
make_shared
<
deleteBLSKeyRspMessage
>
(
_d
);
break
;
case
ENUM_GET_DECRYPTION_SHARE_RSP
:
ret
=
make_shared
<
GetDecryptionShareRspMessage
>
(
_d
);
break
;
default
:
break
;
}
...
...
@@ -320,7 +326,8 @@ const std::map<string, int> ZMQMessage::requests{
{
GET_VV_REQ
,
7
},
{
GET_SECRET_SHARE_REQ
,
8
},
{
DKG_VERIFY_REQ
,
9
},
{
CREATE_BLS_PRIVATE_REQ
,
10
},
{
GET_BLS_PUBLIC_REQ
,
11
},
{
GET_ALL_BLS_PUBLIC_REQ
,
12
},
{
COMPLAINT_RESPONSE_REQ
,
13
},
{
MULT_G2_REQ
,
14
},
{
IS_POLY_EXISTS_REQ
,
15
},
{
GET_SERVER_STATUS_REQ
,
16
},
{
GET_SERVER_VERSION_REQ
,
17
},
{
DELETE_BLS_KEY_REQ
,
18
}
{
GET_SERVER_STATUS_REQ
,
16
},
{
GET_SERVER_VERSION_REQ
,
17
},
{
DELETE_BLS_KEY_REQ
,
18
},
{
GET_DECRYPTION_SHARE_REQ
,
19
}
};
const
std
::
map
<
string
,
int
>
ZMQMessage
::
responses
{
...
...
@@ -329,5 +336,6 @@ const std::map<string, int> ZMQMessage::responses {
{
GET_VV_RSP
,
7
},
{
GET_SECRET_SHARE_RSP
,
8
},
{
DKG_VERIFY_RSP
,
9
},
{
CREATE_BLS_PRIVATE_RSP
,
10
},
{
GET_BLS_PUBLIC_RSP
,
11
},
{
GET_ALL_BLS_PUBLIC_RSP
,
12
},
{
COMPLAINT_RESPONSE_RSP
,
13
},
{
MULT_G2_RSP
,
14
},
{
IS_POLY_EXISTS_RSP
,
15
},
{
GET_SERVER_STATUS_RSP
,
16
},
{
GET_SERVER_VERSION_RSP
,
17
},
{
DELETE_BLS_KEY_RSP
,
18
}
{
GET_SERVER_STATUS_RSP
,
16
},
{
GET_SERVER_VERSION_RSP
,
17
},
{
DELETE_BLS_KEY_RSP
,
18
},
{
GET_DECRYPTION_SHARE_RSP
,
19
}
};
zmq_src/ZMQMessage.h
View file @
9b090a3a
...
...
@@ -91,6 +91,8 @@ public:
static
constexpr
const
char
*
GET_SERVER_VERSION_RSP
=
"getServerVersionRsp"
;
static
constexpr
const
char
*
DELETE_BLS_KEY_REQ
=
"deleteBLSKeyReq"
;
static
constexpr
const
char
*
DELETE_BLS_KEY_RSP
=
"deleteBLSKeyRsp"
;
static
constexpr
const
char
*
GET_DECRYPTION_SHARE_REQ
=
"getDecryptionShareReq"
;
static
constexpr
const
char
*
GET_DECRYPTION_SHARE_RSP
=
"getDecryptionShareRsp"
;
static
const
std
::
map
<
string
,
int
>
requests
;
static
const
std
::
map
<
string
,
int
>
responses
;
...
...
@@ -98,11 +100,11 @@ public:
enum
Requests
{
ENUM_BLS_SIGN_REQ
,
ENUM_ECDSA_SIGN_REQ
,
ENUM_IMPORT_BLS_REQ
,
ENUM_IMPORT_ECDSA_REQ
,
ENUM_GENERATE_ECDSA_REQ
,
ENUM_GET_PUBLIC_ECDSA_REQ
,
ENUM_GENERATE_DKG_POLY_REQ
,
ENUM_GET_VV_REQ
,
ENUM_GET_SECRET_SHARE_REQ
,
ENUM_DKG_VERIFY_REQ
,
ENUM_CREATE_BLS_PRIVATE_REQ
,
ENUM_GET_BLS_PUBLIC_REQ
,
ENUM_GET_ALL_BLS_PUBLIC_REQ
,
ENUM_COMPLAINT_RESPONSE_REQ
,
ENUM_MULT_G2_REQ
,
ENUM_IS_POLY_EXISTS_REQ
,
ENUM_GET_SERVER_STATUS_REQ
,
ENUM_GET_SERVER_VERSION_REQ
,
ENUM_DELETE_BLS_KEY_REQ
};
ENUM_GET_SERVER_STATUS_REQ
,
ENUM_GET_SERVER_VERSION_REQ
,
ENUM_DELETE_BLS_KEY_REQ
,
ENUM_GET_DECRYPTION_SHARE_REQ
};
enum
Responses
{
ENUM_BLS_SIGN_RSP
,
ENUM_ECDSA_SIGN_RSP
,
ENUM_IMPORT_BLS_RSP
,
ENUM_IMPORT_ECDSA_RSP
,
ENUM_GENERATE_ECDSA_RSP
,
ENUM_GET_PUBLIC_ECDSA_RSP
,
ENUM_GENERATE_DKG_POLY_RSP
,
ENUM_GET_VV_RSP
,
ENUM_GET_SECRET_SHARE_RSP
,
ENUM_DKG_VERIFY_RSP
,
ENUM_CREATE_BLS_PRIVATE_RSP
,
ENUM_GET_BLS_PUBLIC_RSP
,
ENUM_GET_ALL_BLS_PUBLIC_RSP
,
ENUM_COMPLAINT_RESPONSE_RSP
,
ENUM_MULT_G2_RSP
,
ENUM_IS_POLY_EXISTS_RSP
,
ENUM_GET_SERVER_STATUS_RSP
,
ENUM_GET_SERVER_VERSION_RSP
,
ENUM_DELETE_BLS_KEY_RSP
};
ENUM_GET_SERVER_STATUS_RSP
,
ENUM_GET_SERVER_VERSION_RSP
,
ENUM_DELETE_BLS_KEY_RSP
,
ENUM_GET_DECRYPTION_SHARE_RSP
};
explicit
ZMQMessage
(
shared_ptr
<
rapidjson
::
Document
>
&
_d
)
:
d
(
_d
)
{};
...
...
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