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
d77c39d5
Unverified
Commit
d77c39d5
authored
Feb 03, 2021
by
kladko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug/SKALE-3751-enable-zeromq
parent
edf533cc
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
9 deletions
+50
-9
ZMQClient.cpp
ZMQClient.cpp
+47
-8
ZMQClient.h
ZMQClient.h
+3
-1
No files found.
ZMQClient.cpp
View file @
d77c39d5
...
...
@@ -48,7 +48,6 @@ shared_ptr <ZMQMessage> ZMQClient::doRequestReply(Json::Value &_req) {
CHECK_STATE
(
!
certificate
.
empty
());
CHECK_STATE
(
!
key
.
empty
());
_req
[
"cert"
]
=
certificate
;
string
msgToSign
=
fastWriter
.
write
(
_req
);
...
...
@@ -57,7 +56,7 @@ shared_ptr <ZMQMessage> ZMQClient::doRequestReply(Json::Value &_req) {
msgToSign
=
std
::
regex_replace
(
msgToSign
,
r
,
""
);
_req
[
"msgSig"
]
=
signString
(
msgToSign
);
_req
[
"msgSig"
]
=
signString
(
pkey
,
msgToSign
);
}
string
reqStr
=
fastWriter
.
write
(
_req
);
...
...
@@ -142,7 +141,46 @@ string ZMQClient::readFileIntoString(const string &_fileName) {
}
string
ZMQClient
::
signString
(
const
string
&
_str
)
{
void
ZMQClient
::
verifySig
(
EVP_PKEY
*
_pubkey
,
const
string
&
_str
,
const
string
_sig
)
{
CHECK_STATE
(
_pubkey
);
vector
<
uint8_t
>
binSig
(
256
,
0
);
uint64_t
binLen
=
0
;
CHECK_STATE
(
hex2carray
(
_sig
.
c_str
(),
&
binLen
,
binSig
.
data
(),
binSig
.
size
()));
CHECK_STATE
(
binLen
>
0
);
EVP_MD_CTX
*
mdctx
=
NULL
;
int
ret
=
0
;
size_t
slen
=
0
;
CHECK_STATE
(
mdctx
=
EVP_MD_CTX_create
());
CHECK_STATE
((
EVP_DigestVerifyInit
(
mdctx
,
NULL
,
EVP_sha256
(),
NULL
,
_pubkey
)
==
1
));
CHECK_STATE
(
EVP_DigestVerifyUpdate
(
mdctx
,
_str
.
c_str
(),
_str
.
size
())
==
1
);
/* First call EVP_DigestSignFinal with a NULL sig parameter to obtain the length of the
* signature. Length is returned in slen */
CHECK_STATE
(
EVP_DigestVerifyFinal
(
mdctx
,
binSig
.
data
(),
binLen
)
==
1
);
if
(
mdctx
)
EVP_MD_CTX_destroy
(
mdctx
);
return
;
}
string
ZMQClient
::
signString
(
EVP_PKEY
*
_pkey
,
const
string
&
_str
)
{
CHECK_STATE
(
_pkey
);
EVP_MD_CTX
*
mdctx
=
NULL
;
int
ret
=
0
;
...
...
@@ -153,7 +191,7 @@ string ZMQClient::signString(const string& _str) {
CHECK_STATE
(
mdctx
=
EVP_MD_CTX_create
());
CHECK_STATE
((
EVP_DigestSignInit
(
mdctx
,
NULL
,
EVP_sha256
(),
NULL
,
pkey
)
==
1
));
CHECK_STATE
((
EVP_DigestSignInit
(
mdctx
,
NULL
,
EVP_sha256
(),
NULL
,
_
pkey
)
==
1
));
CHECK_STATE
(
EVP_DigestSignUpdate
(
mdctx
,
_str
.
c_str
(),
_str
.
size
())
==
1
);
...
...
@@ -203,7 +241,8 @@ ZMQClient::ZMQClient(const string &ip, uint16_t port, bool _sign, const string &
CHECK_STATE
(
pkey
);
BIO_free
(
bo
);
signString
(
"sample"
);
...
...
@@ -214,9 +253,6 @@ ZMQClient::ZMQClient(const string &ip, uint16_t port, bool _sign, const string &
CHECK_STATE
(
bo2
);
BIO_write
(
bo2
,
pubKeyStr
.
c_str
(),
pubKeyStr
.
size
());
cerr
<<
pubKeyStr
;
sleep
(
5
);
PEM_read_bio_X509
(
bo2
,
&
x509Cert
,
0
,
0
);
CHECK_STATE
(
x509Cert
);
...
...
@@ -225,6 +261,9 @@ ZMQClient::ZMQClient(const string &ip, uint16_t port, bool _sign, const string &
BIO_free
(
bo2
);
auto
sig
=
signString
(
pkey
,
"sample"
);
verifySig
(
pubkey
,
"sample"
,
sig
);
}
else
{
CHECK_STATE
(
_certFileName
.
empty
());
CHECK_STATE
(
_certKeyName
.
empty
());
...
...
ZMQClient.h
View file @
d77c39d5
...
...
@@ -88,7 +88,9 @@ public:
void
reconnect
()
;
string
signString
(
const
string
&
_str
);
static
string
signString
(
EVP_PKEY
*
_pkey
,
const
string
&
_str
);
static
void
verifySig
(
EVP_PKEY
*
_pubkey
,
const
string
&
_str
,
const
string
_sig
);
string
blsSignMessageHash
(
const
std
::
string
&
keyShareName
,
const
std
::
string
&
messageHash
,
int
t
,
int
n
);
...
...
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