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
d505b35a
Unverified
Commit
d505b35a
authored
Feb 01, 2021
by
kladko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug/SKALE-3751-enable-zeromq
parent
0d8128ad
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
71 additions
and
3 deletions
+71
-3
BLSCrypto.cpp
BLSCrypto.cpp
+1
-0
ZMQClient.cpp
ZMQClient.cpp
+61
-3
ZMQClient.h
ZMQClient.h
+9
-0
sgx_util
sgx_util
+0
-0
No files found.
BLSCrypto.cpp
View file @
d505b35a
...
@@ -78,6 +78,7 @@ int char2int(char _input) {
...
@@ -78,6 +78,7 @@ int char2int(char _input) {
vector
<
char
>
carray2Hex
(
const
unsigned
char
*
d
,
uint64_t
_len
)
{
vector
<
char
>
carray2Hex
(
const
unsigned
char
*
d
,
uint64_t
_len
)
{
CHECK_STATE
(
d
);
CHECK_STATE
(
d
);
vector
<
char
>
_hexArray
(
2
*
_len
+
1
);
vector
<
char
>
_hexArray
(
2
*
_len
+
1
);
char
hexval
[
16
]
=
{
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
char
hexval
[
16
]
=
{
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
...
...
ZMQClient.cpp
View file @
d505b35a
...
@@ -25,11 +25,14 @@
...
@@ -25,11 +25,14 @@
#include <sys/types.h>
#include <sys/types.h>
#include <sys/syscall.h>
#include <sys/syscall.h>
#include <fstream>
#include <fstream>
#include <streambuf>
#include <streambuf>
#include <regex>
#include "common.h"
#include "common.h"
#include "BLSCrypto.h"
#include "BLSSignReqMessage.h"
#include "BLSSignReqMessage.h"
#include "BLSSignRspMessage.h"
#include "BLSSignRspMessage.h"
#include "ECDSASignReqMessage.h"
#include "ECDSASignReqMessage.h"
...
@@ -45,8 +48,16 @@ shared_ptr <ZMQMessage> ZMQClient::doRequestReply(Json::Value &_req) {
...
@@ -45,8 +48,16 @@ shared_ptr <ZMQMessage> ZMQClient::doRequestReply(Json::Value &_req) {
CHECK_STATE
(
!
certificate
.
empty
());
CHECK_STATE
(
!
certificate
.
empty
());
CHECK_STATE
(
!
key
.
empty
());
CHECK_STATE
(
!
key
.
empty
());
_req
[
"cert"
]
=
certificate
;
_req
[
"cert"
]
=
certificate
;
_req
[
"msgSig"
]
=
"haha"
;
string
msgToSign
=
fastWriter
.
write
(
_req
);
std
::
regex
r
(
"
\\
s+"
);
msgToSign
=
std
::
regex_replace
(
msgToSign
,
r
,
""
);
_req
[
"msgSig"
]
=
signString
(
msgToSign
);
}
}
string
reqStr
=
fastWriter
.
write
(
_req
);
string
reqStr
=
fastWriter
.
write
(
_req
);
...
@@ -124,15 +135,52 @@ string ZMQClient::doZmqRequestReply(string &_req) {
...
@@ -124,15 +135,52 @@ string ZMQClient::doZmqRequestReply(string &_req) {
}
}
string
ZMQClient
::
readFileIntoString
(
const
string
&
_fileName
)
{
string
ZMQClient
::
readFileIntoString
(
const
string
&
_fileName
)
{
ifstream
t
(
_fileName
);
ifstream
t
(
_fileName
);
string
str
((
istreambuf_iterator
<
char
>
(
t
)),
istreambuf_iterator
<
char
>
());
string
str
((
istreambuf_iterator
<
char
>
(
t
)),
istreambuf_iterator
<
char
>
());
return
str
;
return
str
;
}
}
string
ZMQClient
::
signString
(
const
string
&
_str
)
{
EVP_MD_CTX
*
mdctx
=
NULL
;
int
ret
=
0
;
unsigned
char
*
signature
=
NULL
;
auto
sig
=
&
signature
;
size_t
slen
=
0
;
CHECK_STATE
(
mdctx
=
EVP_MD_CTX_create
());
CHECK_STATE
((
EVP_DigestSignInit
(
mdctx
,
NULL
,
EVP_sha256
(),
NULL
,
pkey
)
==
1
));
CHECK_STATE
(
EVP_DigestSignUpdate
(
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_DigestSignFinal
(
mdctx
,
NULL
,
&
slen
)
==
1
);
signature
=
(
unsigned
char
*
)
OPENSSL_malloc
(
sizeof
(
unsigned
char
)
*
slen
);
CHECK_STATE
(
signature
);
CHECK_STATE
(
EVP_DigestSignFinal
(
mdctx
,
signature
,
&
slen
)
==
1
);
auto
hexSig
=
carray2Hex
(
signature
,
slen
);
string
hexStringSig
(
hexSig
.
begin
(),
hexSig
.
end
());
/* Clean up */
if
(
signature
)
OPENSSL_free
(
signature
);
if
(
mdctx
)
EVP_MD_CTX_destroy
(
mdctx
);
return
hexStringSig
;
}
ZMQClient
::
ZMQClient
(
const
string
&
ip
,
uint16_t
port
,
bool
_sign
,
const
string
&
_certFileName
,
ZMQClient
::
ZMQClient
(
const
string
&
ip
,
uint16_t
port
,
bool
_sign
,
const
string
&
_certFileName
,
const
string
&
_certKeyName
)
:
ctx
(
1
),
sign
(
_sign
),
const
string
&
_certKeyName
)
:
ctx
(
1
),
sign
(
_sign
),
certKeyName
(
_certKeyName
),
certFileName
(
_certFileName
)
{
certKeyName
(
_certKeyName
),
certFileName
(
_certFileName
)
{
spdlog
::
info
(
"Initing ZMQClient. Sign:{} "
,
_sign
);
spdlog
::
info
(
"Initing ZMQClient. Sign:{} "
,
_sign
);
...
@@ -147,6 +195,16 @@ ZMQClient::ZMQClient(const string &ip, uint16_t port, bool _sign, const string &
...
@@ -147,6 +195,16 @@ ZMQClient::ZMQClient(const string &ip, uint16_t port, bool _sign, const string &
key
=
readFileIntoString
(
_certKeyName
);
key
=
readFileIntoString
(
_certKeyName
);
CHECK_STATE
(
!
key
.
empty
());
CHECK_STATE
(
!
key
.
empty
());
BIO
*
bo
=
BIO_new
(
BIO_s_mem
());
CHECK_STATE
(
bo
);
BIO_write
(
bo
,
key
.
c_str
(),
key
.
size
());
PEM_read_bio_PrivateKey
(
bo
,
&
pkey
,
0
,
0
);
CHECK_STATE
(
pkey
);
BIO_free
(
bo
);
signString
(
"sample"
);
}
else
{
}
else
{
CHECK_STATE
(
_certFileName
.
empty
());
CHECK_STATE
(
_certFileName
.
empty
());
CHECK_STATE
(
_certKeyName
.
empty
());
CHECK_STATE
(
_certKeyName
.
empty
());
...
...
ZMQClient.h
View file @
d505b35a
...
@@ -27,6 +27,12 @@
...
@@ -27,6 +27,12 @@
#ifndef SGXWALLET_ZMQCLIENT_H
#ifndef SGXWALLET_ZMQCLIENT_H
#define SGXWALLET_ZMQCLIENT_H
#define SGXWALLET_ZMQCLIENT_H
#include <openssl/pem.h>
#include <openssl/evp.h>
#include <openssl/err.h>
#include <openssl/sha.h>
#include <openssl/rand.h>
#include "third_party/spdlog/spdlog.h"
#include "third_party/spdlog/spdlog.h"
#include <zmq.hpp>
#include <zmq.hpp>
...
@@ -44,6 +50,7 @@ class ZMQClient {
...
@@ -44,6 +50,7 @@ class ZMQClient {
private
:
private
:
EVP_PKEY
*
pkey
=
0
;
bool
sign
=
true
;
bool
sign
=
true
;
string
certFileName
=
""
;
string
certFileName
=
""
;
...
@@ -78,6 +85,8 @@ public:
...
@@ -78,6 +85,8 @@ public:
void
reconnect
()
;
void
reconnect
()
;
string
signString
(
const
string
&
_str
);
string
blsSignMessageHash
(
const
std
::
string
&
keyShareName
,
const
std
::
string
&
messageHash
,
int
t
,
int
n
);
string
blsSignMessageHash
(
const
std
::
string
&
keyShareName
,
const
std
::
string
&
messageHash
,
int
t
,
int
n
);
string
ecdsaSignMessageHash
(
int
base
,
const
std
::
string
&
keyName
,
const
std
::
string
&
messageHash
);
string
ecdsaSignMessageHash
(
int
base
,
const
std
::
string
&
keyName
,
const
std
::
string
&
messageHash
);
...
...
sgx_util
View file @
d505b35a
No preview for this file type
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