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
41d00a8f
Unverified
Commit
41d00a8f
authored
Jul 30, 2021
by
Oleh Nikolaiev
Committed by
GitHub
Jul 30, 2021
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #338 from skalenetwork/feature/SKALE-4262-add-E-flag
Feature/skale 4262 add e flag
parents
afbf4f0f
8a11d1f9
Changes
25
Hide whitespace changes
Inline
Side-by-side
Showing
25 changed files
with
142 additions
and
236 deletions
+142
-236
DockerfileBase
DockerfileBase
+14
-14
LevelDB.h
LevelDB.h
+1
-4
SGXWalletServer.hpp
SGXWalletServer.hpp
+1
-4
ServerInit.cpp
ServerInit.cpp
+3
-3
ServerInit.h
ServerInit.h
+1
-1
start.sh
docker/start.sh
+1
-1
docker-compose.yml
run_sgx/docker-compose.yml
+1
-1
docker-compose.yml
run_sgx_sim/docker-compose.yml
+1
-1
install_packages.sh
scripts/install_packages.sh
+1
-1
AESUtils.c
secure_enclave/AESUtils.c
+1
-7
AESUtils.h
secure_enclave/AESUtils.h
+0
-3
EnclaveCommon.cpp
secure_enclave/EnclaveCommon.cpp
+0
-1
secure_enclave.c
secure_enclave/secure_enclave.c
+0
-5
sgxwall.cpp
sgxwall.cpp
+9
-3
testw.cpp
testw.cpp
+5
-5
BLSSignRspMessage.cpp
zmq_src/BLSSignRspMessage.cpp
+0
-30
BLSSignRspMessage.h
zmq_src/BLSSignRspMessage.h
+0
-43
ECDSASignRspMessage.cpp
zmq_src/ECDSASignRspMessage.cpp
+0
-46
ECDSASignRspMessage.h
zmq_src/ECDSASignRspMessage.h
+0
-42
ReqMessage.cpp
zmq_src/ReqMessage.cpp
+51
-1
ZMQClient.cpp
zmq_src/ZMQClient.cpp
+1
-1
ZMQMessage.cpp
zmq_src/ZMQMessage.cpp
+23
-7
ZMQMessage.h
zmq_src/ZMQMessage.h
+16
-3
ZMQServer.cpp
zmq_src/ZMQServer.cpp
+7
-6
ZMQServer.h
zmq_src/ZMQServer.h
+5
-3
No files found.
DockerfileBase
View file @
41d00a8f
FROM ubuntu:18.04
FROM ubuntu:18.04
RUN apt-get update && apt-get install
-y \
RUN apt-get update && apt-get install -y \
autoconf \
autoconf \
automake \
automake \
build-essential \
build-essential \
...
@@ -48,19 +48,19 @@ COPY . /usr/src/sdk
...
@@ -48,19 +48,19 @@ COPY . /usr/src/sdk
RUN ls /usr/src/sdk/autoconf.bash
RUN ls /usr/src/sdk/autoconf.bash
WORKDIR /usr/src/sdk
WORKDIR /usr/src/sdk
RUN
apt update && \
RUN apt update && \
apt install -yq apt-utils && \
apt install -yq apt-utils && \
apt install -yq --no-install-recommends python-yaml vim \
apt install -yq --no-install-recommends python-yaml vim \
telnet git ca-certificates perl \
telnet git ca-certificates perl \
reprepro libboost-all-dev alien uuid-dev libxml2-dev ccache \
reprepro libboost-all-dev alien uuid-dev libxml2-dev ccache \
yasm flex bison libprocps-dev ccache texinfo \
yasm flex bison libprocps-dev ccache texinfo \
libjsonrpccpp-dev curl libjsonrpccpp-tools && \
libjsonrpccpp-dev curl libjsonrpccpp-tools && \
ln -s /usr/bin/ccache /usr/local/bin/clang && \
ln -s /usr/bin/ccache /usr/local/bin/clang && \
ln -s /usr/bin/ccache /usr/local/bin/clang++ && \
ln -s /usr/bin/ccache /usr/local/bin/clang++ && \
ln -s /usr/bin/ccache /usr/local/bin/gcc && \
ln -s /usr/bin/ccache /usr/local/bin/gcc && \
ln -s /usr/bin/ccache /usr/local/bin/g++ && \
ln -s /usr/bin/ccache /usr/local/bin/g++ && \
ln -s /usr/bin/ccache /usr/local/bin/cc && \
ln -s /usr/bin/ccache /usr/local/bin/cc && \
ln -s /usr/bin/ccache /usr/local/bin/c++
ln -s /usr/bin/ccache /usr/local/bin/c++
RUN cd scripts && ./build_deps.py && \
RUN cd scripts && ./build_deps.py && \
wget --progress=dot:mega -O - https://github.com/intel/dynamic-application-loader-host-interface/archive/072d233296c15d0dcd1fb4570694d0244729f87b.tar.gz | tar -xz && \
wget --progress=dot:mega -O - https://github.com/intel/dynamic-application-loader-host-interface/archive/072d233296c15d0dcd1fb4570694d0244729f87b.tar.gz | tar -xz && \
...
...
LevelDB.h
View file @
41d00a8f
...
@@ -14,7 +14,7 @@
...
@@ -14,7 +14,7 @@
GNU Affero General Public License for more details.
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
You should have received a copy of the GNU Affero General Public License
along with sgxwallet.
If not, see <https://www.gnu.org/licenses/>.
along with sgxwallet. If not, see <https://www.gnu.org/licenses/>.
@file LevelDB.h
@file LevelDB.h
@author Stan Kladko
@author Stan Kladko
...
@@ -54,7 +54,6 @@ class LevelDB {
...
@@ -54,7 +54,6 @@ class LevelDB {
static
string
sgx_data_folder
;
static
string
sgx_data_folder
;
public
:
public
:
static
void
initDataFolderAndDBs
();
static
void
initDataFolderAndDBs
();
...
@@ -104,8 +103,6 @@ public:
...
@@ -104,8 +103,6 @@ public:
virtual
~
LevelDB
();
virtual
~
LevelDB
();
static
const
string
&
getSgxDataFolder
();
static
const
string
&
getSgxDataFolder
();
};
};
...
...
SGXWalletServer.hpp
View file @
41d00a8f
...
@@ -14,7 +14,7 @@
...
@@ -14,7 +14,7 @@
GNU Affero General Public License for more details.
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
You should have received a copy of the GNU Affero General Public License
along with sgxwallet.
If not, see <https://www.gnu.org/licenses/>.
along with sgxwallet. If not, see <https://www.gnu.org/licenses/>.
@file SGXWalletServer.hpp
@file SGXWalletServer.hpp
@author Stan Kladko
@author Stan Kladko
...
@@ -48,12 +48,9 @@ class SGXWalletServer : public AbstractStubServer {
...
@@ -48,12 +48,9 @@ class SGXWalletServer : public AbstractStubServer {
static
map
<
string
,
string
>
ecdsaRequests
;
static
map
<
string
,
string
>
ecdsaRequests
;
static
recursive_mutex
ecdsaRequestsLock
;
static
recursive_mutex
ecdsaRequestsLock
;
static
void
checkForDuplicate
(
map
<
string
,
string
>
&
_map
,
recursive_mutex
&
_m
,
const
string
&
_key
,
static
void
checkForDuplicate
(
map
<
string
,
string
>
&
_map
,
recursive_mutex
&
_m
,
const
string
&
_key
,
const
string
&
_value
);
const
string
&
_value
);
public
:
public
:
static
bool
verifyCert
(
string
&
_certFileName
);
static
bool
verifyCert
(
string
&
_certFileName
);
...
...
ServerInit.cpp
View file @
41d00a8f
...
@@ -14,7 +14,7 @@
...
@@ -14,7 +14,7 @@
GNU Affero General Public License for more details.
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
You should have received a copy of the GNU Affero General Public License
along with sgxwallet.
If not, see <https://www.gnu.org/licenses/>.
along with sgxwallet. If not, see <https://www.gnu.org/licenses/>.
@file ServerInit.cpp
@file ServerInit.cpp
@author Stan Kladko
@author Stan Kladko
...
@@ -160,7 +160,7 @@ uint64_t initEnclave() {
...
@@ -160,7 +160,7 @@ uint64_t initEnclave() {
}
}
void
initAll
(
uint32_t
_logLevel
,
bool
_checkCert
,
void
initAll
(
uint32_t
_logLevel
,
bool
_checkCert
,
bool
_checkZMQSig
,
bool
_autoSign
,
bool
_generateTestKeys
)
{
bool
_checkZMQSig
,
bool
_autoSign
,
bool
_generateTestKeys
,
bool
_checkKeyOwnership
)
{
static
atomic
<
bool
>
sgxServerInited
(
false
);
static
atomic
<
bool
>
sgxServerInited
(
false
);
static
mutex
initMutex
;
static
mutex
initMutex
;
...
@@ -209,7 +209,7 @@ void initAll(uint32_t _logLevel, bool _checkCert,
...
@@ -209,7 +209,7 @@ void initAll(uint32_t _logLevel, bool _checkCert,
SGXRegistrationServer
::
initRegistrationServer
(
_autoSign
);
SGXRegistrationServer
::
initRegistrationServer
(
_autoSign
);
CSRManagerServer
::
initCSRManagerServer
();
CSRManagerServer
::
initCSRManagerServer
();
SGXInfoServer
::
initInfoServer
(
_logLevel
,
_checkCert
,
_autoSign
,
_generateTestKeys
);
SGXInfoServer
::
initInfoServer
(
_logLevel
,
_checkCert
,
_autoSign
,
_generateTestKeys
);
ZMQServer
::
initZMQServer
(
_checkZMQSig
);
ZMQServer
::
initZMQServer
(
_checkZMQSig
,
_checkKeyOwnership
);
sgxServerInited
=
true
;
sgxServerInited
=
true
;
}
catch
(
SGXException
&
_e
)
{
}
catch
(
SGXException
&
_e
)
{
...
...
ServerInit.h
View file @
41d00a8f
...
@@ -32,7 +32,7 @@
...
@@ -32,7 +32,7 @@
#define EXTERNC
#define EXTERNC
#endif
#endif
EXTERNC
void
initAll
(
uint32_t
_logLevel
,
bool
_checkCert
,
bool
_checkZMQSig
,
bool
_autoSign
,
bool
_generateTestKeys
);
EXTERNC
void
initAll
(
uint32_t
_logLevel
,
bool
_checkCert
,
bool
_checkZMQSig
,
bool
_autoSign
,
bool
_generateTestKeys
,
bool
_checkKeyOwnership
);
void
exitAll
();
void
exitAll
();
...
...
docker/start.sh
View file @
41d00a8f
...
@@ -47,6 +47,6 @@ sleep 5
...
@@ -47,6 +47,6 @@ sleep 5
./testw.py
./testw.py
else
else
sleep
3
sleep
3
./sgxwallet
$1
$2
$3
$4
$5
./sgxwallet
$1
$2
$3
$4
$5
$6
fi
fi
run_sgx/docker-compose.yml
View file @
41d00a8f
...
@@ -21,7 +21,7 @@ services:
...
@@ -21,7 +21,7 @@ services:
options
:
options
:
max-size
:
"
10m"
max-size
:
"
10m"
max-file
:
"
4"
max-file
:
"
4"
command
:
-s -y -d
command
:
-s -y -d
-e
healthcheck
:
healthcheck
:
test
:
[
"
CMD"
,
"
ls"
,
"
/dev/isgx"
,
"
/dev/mei0"
]
test
:
[
"
CMD"
,
"
ls"
,
"
/dev/isgx"
,
"
/dev/mei0"
]
run_sgx_sim/docker-compose.yml
View file @
41d00a8f
...
@@ -18,4 +18,4 @@ services:
...
@@ -18,4 +18,4 @@ services:
options
:
options
:
max-size
:
"
10m"
max-size
:
"
10m"
max-file
:
"
4"
max-file
:
"
4"
command
:
-s -y
command
:
-s -y
-e
scripts/install_packages.sh
View file @
41d00a8f
...
@@ -2,4 +2,4 @@
...
@@ -2,4 +2,4 @@
sudo
apt update
sudo
apt update
sudo
apt
install
-y
build-essential make gcc g++ yasm python libprotobuf10 flex bison automake
sudo
apt
install
-y
build-essential make gcc g++ yasm python libprotobuf10 flex bison automake
sudo
apt
install
-y
ccache cmake ccache autoconf texinfo libgcrypt20-dev libgnutls28-dev libtool pkg-config
sudo
apt
install
-y
ccache cmake ccache autoconf texinfo libgcrypt20-dev libgnutls28-dev libtool pkg-config
sudo
apt
install
-y
ocaml ocamlbuid
sudo
apt
install
-y
ocaml ocamlbui
l
d
secure_enclave/AESUtils.c
View file @
41d00a8f
...
@@ -21,25 +21,19 @@
...
@@ -21,25 +21,19 @@
@date 2020
@date 2020
*/
*/
#include "sgx_trts.h"
#include "sgx_trts.h"
#include "sgx_tcrypto.h"
#include "sgx_tcrypto.h"
#include "stdlib.h"
#include "stdlib.h"
#include <string.h>
#include <string.h>
#include "AESUtils.h"
#include "AESUtils.h"
sgx_aes_gcm_128bit_key_t
AES_key
[
1024
];
sgx_aes_gcm_128bit_key_t
AES_key
[
1024
];
#define SAFE_CHAR_BUF(__X__, __Y__) ;char __X__ [ __Y__ ]; memset(__X__, 0, __Y__);
#define SAFE_CHAR_BUF(__X__, __Y__) ;char __X__ [ __Y__ ]; memset(__X__, 0, __Y__);
int
AES_encrypt
(
char
*
message
,
uint8_t
*
encr_message
,
uint64_t
encrBufLen
,
unsigned
char
type
,
int
AES_encrypt
(
char
*
message
,
uint8_t
*
encr_message
,
uint64_t
encrBufLen
,
unsigned
char
type
,
unsigned
char
exportable
,
uint64_t
*
resultLen
)
{
unsigned
char
exportable
,
uint64_t
*
resultLen
)
{
if
(
!
type
)
{
if
(
!
type
)
{
LOG_ERROR
(
"Null type in AES_encrypt"
);
LOG_ERROR
(
"Null type in AES_encrypt"
);
return
-
1
;
return
-
1
;
...
...
secure_enclave/AESUtils.h
View file @
41d00a8f
...
@@ -32,7 +32,6 @@ int AES_decrypt(uint8_t *encr_message, uint64_t length, char *message, uint64_t
...
@@ -32,7 +32,6 @@ int AES_decrypt(uint8_t *encr_message, uint64_t length, char *message, uint64_t
uint8_t
*
type
,
uint8_t
*
exportable
)
;
uint8_t
*
type
,
uint8_t
*
exportable
)
;
#define ECDSA '1'
#define ECDSA '1'
#define BLS '2'
#define BLS '2'
#define DKG '3'
#define DKG '3'
...
@@ -40,6 +39,4 @@ int AES_decrypt(uint8_t *encr_message, uint64_t length, char *message, uint64_t
...
@@ -40,6 +39,4 @@ int AES_decrypt(uint8_t *encr_message, uint64_t length, char *message, uint64_t
#define EXPORTABLE '1'
#define EXPORTABLE '1'
#define NON_EXPORTABLE '2'
#define NON_EXPORTABLE '2'
#endif //SGXD_AESUTILS_H
#endif //SGXD_AESUTILS_H
secure_enclave/EnclaveCommon.cpp
View file @
41d00a8f
...
@@ -171,7 +171,6 @@ void enclave_init() {
...
@@ -171,7 +171,6 @@ void enclave_init() {
return
;
return
;
inited
=
1
;
inited
=
1
;
LOG_INFO
(
"Initing libff"
);
LOG_INFO
(
"Initing libff"
);
try
{
try
{
...
...
secure_enclave/secure_enclave.c
View file @
41d00a8f
...
@@ -66,7 +66,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
...
@@ -66,7 +66,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define INIT_ERROR_STATE *errString = 0; *errStatus = UNKNOWN_ERROR;
#define INIT_ERROR_STATE *errString = 0; *errStatus = UNKNOWN_ERROR;
#define SET_SUCCESS *errStatus = 0;
#define SET_SUCCESS *errStatus = 0;
#define CHECK_STATE(_EXPRESSION_) \
#define CHECK_STATE(_EXPRESSION_) \
if (!(_EXPRESSION_)) { \
if (!(_EXPRESSION_)) { \
LOG_ERROR("State check failed::");LOG_ERROR(#_EXPRESSION_); \
LOG_ERROR("State check failed::");LOG_ERROR(#_EXPRESSION_); \
...
@@ -91,7 +90,6 @@ LOG_ERROR(errString); \
...
@@ -91,7 +90,6 @@ LOG_ERROR(errString); \
goto clean; \
goto clean; \
};
};
#define CHECK_STATUS2(__ERRMESSAGE__) if (status != SGX_SUCCESS) { \
#define CHECK_STATUS2(__ERRMESSAGE__) if (status != SGX_SUCCESS) { \
snprintf(errString, BUF_LEN, __ERRMESSAGE__, status); \
snprintf(errString, BUF_LEN, __ERRMESSAGE__, status); \
LOG_ERROR(errString); \
LOG_ERROR(errString); \
...
@@ -138,10 +136,8 @@ void trustedEnclaveInit(uint64_t _logLevel) {
...
@@ -138,10 +136,8 @@ void trustedEnclaveInit(uint64_t _logLevel) {
LOG_INFO
(
"Calling enclave init"
);
LOG_INFO
(
"Calling enclave init"
);
enclave_init
();
enclave_init
();
LOG_INFO
(
"Reading random"
);
LOG_INFO
(
"Reading random"
);
globalRandom
=
calloc
(
32
,
1
);
globalRandom
=
calloc
(
32
,
1
);
...
@@ -228,7 +224,6 @@ void get_global_random(unsigned char *_randBuff, uint64_t _size) {
...
@@ -228,7 +224,6 @@ void get_global_random(unsigned char *_randBuff, uint64_t _size) {
memcpy
(
_randBuff
,
globalRandom
,
_size
);
memcpy
(
_randBuff
,
globalRandom
,
_size
);
}
}
void
sealHexSEK
(
int
*
errStatus
,
char
*
errString
,
void
sealHexSEK
(
int
*
errStatus
,
char
*
errString
,
uint8_t
*
encrypted_sek
,
uint64_t
*
enc_len
,
char
*
sek_hex
)
{
uint8_t
*
encrypted_sek
,
uint64_t
*
enc_len
,
char
*
sek_hex
)
{
CALL_ONCE
CALL_ONCE
...
...
sgxwall.cpp
View file @
41d00a8f
...
@@ -55,6 +55,7 @@ void SGXWallet::printUsage() {
...
@@ -55,6 +55,7 @@ void SGXWallet::printUsage() {
cerr
<<
" -n Use http instead of https. Default is to use https with a selg-signed server cert. Insecure!
\n
"
;
cerr
<<
" -n Use http instead of https. Default is to use https with a selg-signed server cert. Insecure!
\n
"
;
cerr
<<
" -c Disable client authentication using certificates. Insecure!
\n
"
;
cerr
<<
" -c Disable client authentication using certificates. Insecure!
\n
"
;
cerr
<<
" -s Sign client certificates without human confirmation. Insecure!
\n
"
;
cerr
<<
" -s Sign client certificates without human confirmation. Insecure!
\n
"
;
cerr
<<
" -e Only owner of the key can access it.
\n
"
;
}
}
...
@@ -100,6 +101,7 @@ int main(int argc, char *argv[]) {
...
@@ -100,6 +101,7 @@ int main(int argc, char *argv[]) {
bool
checkClientCertOption
=
true
;
bool
checkClientCertOption
=
true
;
bool
autoSignClientCertOption
=
false
;
bool
autoSignClientCertOption
=
false
;
bool
generateTestKeys
=
false
;
bool
generateTestKeys
=
false
;
bool
checkKeyOwnership
=
true
;
std
::
signal
(
SIGABRT
,
SGXWallet
::
signalHandler
);
std
::
signal
(
SIGABRT
,
SGXWallet
::
signalHandler
);
...
@@ -110,7 +112,7 @@ int main(int argc, char *argv[]) {
...
@@ -110,7 +112,7 @@ int main(int argc, char *argv[]) {
exit
(
-
21
);
exit
(
-
21
);
}
}
while
((
opt
=
getopt
(
argc
,
argv
,
"cshd0abyvVnT"
))
!=
-
1
)
{
while
((
opt
=
getopt
(
argc
,
argv
,
"cshd0abyvVn
e
T"
))
!=
-
1
)
{
switch
(
opt
)
{
switch
(
opt
)
{
case
'h'
:
case
'h'
:
SGXWallet
::
printUsage
();
SGXWallet
::
printUsage
();
...
@@ -136,7 +138,11 @@ int main(int argc, char *argv[]) {
...
@@ -136,7 +138,11 @@ int main(int argc, char *argv[]) {
break
;
break
;
case
'n'
:
case
'n'
:
useHTTPSOption
=
false
;
useHTTPSOption
=
false
;
break
;
checkKeyOwnership
=
false
;
break
;
case
'e'
:
checkKeyOwnership
=
true
;
break
;
case
'a'
:
case
'a'
:
enterBackupKeyOption
=
false
;
enterBackupKeyOption
=
false
;
break
;
break
;
...
@@ -179,7 +185,7 @@ int main(int argc, char *argv[]) {
...
@@ -179,7 +185,7 @@ int main(int argc, char *argv[]) {
}
}
cerr
<<
"Calling initAll ..."
<<
endl
;
cerr
<<
"Calling initAll ..."
<<
endl
;
initAll
(
enclaveLogLevel
,
checkClientCertOption
,
checkClientCertOption
,
autoSignClientCertOption
,
generateTestKeys
);
initAll
(
enclaveLogLevel
,
checkClientCertOption
,
checkClientCertOption
,
autoSignClientCertOption
,
generateTestKeys
,
checkKeyOwnership
);
cerr
<<
"Completed initAll."
<<
endl
;
cerr
<<
"Completed initAll."
<<
endl
;
//check if test keys already exist
//check if test keys already exist
...
...
testw.cpp
View file @
41d00a8f
...
@@ -73,7 +73,7 @@ public:
...
@@ -73,7 +73,7 @@ public:
TestFixture
()
{
TestFixture
()
{
TestUtils
::
resetDB
();
TestUtils
::
resetDB
();
setOptions
(
L_INFO
,
false
,
true
);
setOptions
(
L_INFO
,
false
,
true
);
initAll
(
L_INFO
,
false
,
false
,
true
,
false
);
initAll
(
L_INFO
,
false
,
false
,
true
,
false
,
false
);
}
}
~
TestFixture
()
{
~
TestFixture
()
{
...
@@ -87,7 +87,7 @@ public:
...
@@ -87,7 +87,7 @@ public:
TestFixtureHTTPS
()
{
TestFixtureHTTPS
()
{
TestUtils
::
resetDB
();
TestUtils
::
resetDB
();
setOptions
(
L_INFO
,
true
,
true
);
setOptions
(
L_INFO
,
true
,
true
);
initAll
(
L_INFO
,
false
,
true
,
true
,
false
);
initAll
(
L_INFO
,
false
,
true
,
true
,
false
,
true
);
}
}
~
TestFixtureHTTPS
()
{
~
TestFixtureHTTPS
()
{
...
@@ -101,7 +101,7 @@ public:
...
@@ -101,7 +101,7 @@ public:
TestFixtureZMQSign
()
{
TestFixtureZMQSign
()
{
TestUtils
::
resetDB
();
TestUtils
::
resetDB
();
setOptions
(
L_INFO
,
false
,
true
);
setOptions
(
L_INFO
,
false
,
true
);
initAll
(
L_INFO
,
false
,
true
,
true
,
false
);
initAll
(
L_INFO
,
false
,
true
,
true
,
false
,
false
);
}
}
~
TestFixtureZMQSign
()
{
~
TestFixtureZMQSign
()
{
...
@@ -114,7 +114,7 @@ class TestFixtureNoResetFromBackup {
...
@@ -114,7 +114,7 @@ class TestFixtureNoResetFromBackup {
public
:
public
:
TestFixtureNoResetFromBackup
()
{
TestFixtureNoResetFromBackup
()
{
setFullOptions
(
L_INFO
,
false
,
true
,
true
);
setFullOptions
(
L_INFO
,
false
,
true
,
true
);
initAll
(
L_INFO
,
false
,
false
,
true
,
false
);
initAll
(
L_INFO
,
false
,
false
,
true
,
false
,
false
);
}
}
~
TestFixtureNoResetFromBackup
()
{
~
TestFixtureNoResetFromBackup
()
{
...
@@ -128,7 +128,7 @@ class TestFixtureNoReset {
...
@@ -128,7 +128,7 @@ class TestFixtureNoReset {
public
:
public
:
TestFixtureNoReset
()
{
TestFixtureNoReset
()
{
setOptions
(
L_INFO
,
false
,
true
);
setOptions
(
L_INFO
,
false
,
true
);
initAll
(
L_INFO
,
false
,
false
,
true
,
false
);
initAll
(
L_INFO
,
false
,
false
,
true
,
false
,
false
);
}
}
~
TestFixtureNoReset
()
{
~
TestFixtureNoReset
()
{
...
...
zmq_src/BLSSignRspMessage.cpp
deleted
100644 → 0
View file @
afbf4f0f
/*
Copyright (C) 2018-2019 SKALE Labs
This file is part of sgxwallet.
sgxwallet is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
sgxwallet is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with sgxwallet. If not, see <https://www.gnu.org/licenses/>.
@file BLSRspSignMessage.cpp
@author Stan Kladko
@date 2020
*/
#include "BLSSignRspMessage.h"
#include "SGXWalletServer.hpp"
Json
::
Value
BLSSignRspMessage
::
process
()
{
assert
(
false
);
}
\ No newline at end of file
zmq_src/BLSSignRspMessage.h
deleted
100644 → 0
View file @
afbf4f0f
/*
Copyright (C) 2018-2019 SKALE Labs
This file is part of sgxwallet.
sgxwallet is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
sgxwallet is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with sgxwallet. If not, see <https://www.gnu.org/licenses/>.
@file BLSRspSignMessage.h
@author Stan Kladko
@date 2020
*/
#ifndef SGXWALLET_BLSSIGNRSPMSG_H
#define SGXWALLET_BLSSIGNRSPMSG_H
#include "ZMQMessage.h"
class
BLSSignRspMessage
:
public
ZMQMessage
{
public
:
BLSSignRspMessage
(
shared_ptr
<
rapidjson
::
Document
>&
_d
)
:
ZMQMessage
(
_d
)
{};
virtual
Json
::
Value
process
();
string
getSigShare
()
{
return
getStringRapid
(
"signatureShare"
);
}
};
#endif //SGXWALLET_BLSSIGNRSPMSG_H
zmq_src/ECDSASignRspMessage.cpp
deleted
100644 → 0
View file @
afbf4f0f
/*
Copyright (C) 2018- SKALE Labs
This file is part of sgxwallet.
sgxwallet is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
sgxwallet is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with sgxwallet. If not, see <https://www.gnu.org/licenses/>.
@file ECDSARspSignMessage.cpp
@author Stan Kladko
@date 2020
*/
#include "SGXWalletServer.hpp"
#include "ECDSASignRspMessage.h"
Json
::
Value
ECDSASignRspMessage
::
process
()
{
// never called
assert
(
false
);
}
string
ECDSASignRspMessage
::
getSignature
()
{
string
r
=
getStringRapid
(
"signature_r"
);
string
v
=
getStringRapid
(
"signature_v"
);
string
s
=
getStringRapid
(
"signature_s"
);
auto
ret
=
v
+
":"
+
r
.
substr
(
2
)
+
":"
+
s
.
substr
(
2
);
return
ret
;
}
zmq_src/ECDSASignRspMessage.h
deleted
100644 → 0
View file @
afbf4f0f
/*
Copyright (C) 2018- SKALE Labs
This file is part of sgxwallet.
sgxwallet is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
sgxwallet is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with sgxwallet. If not, see <https://www.gnu.org/licenses/>.
@file ECDSARspSignMessage.h
@author Stan Kladko
@date 2020
*/
#ifndef SGXWALLET_ECDSASIGNRSPMESSAGE_H
#define SGXWALLET_ECDSASIGNRSPMESSAGE_H
#include "ZMQMessage.h"
class
ECDSASignRspMessage
:
public
ZMQMessage
{
public
:
ECDSASignRspMessage
(
shared_ptr
<
rapidjson
::
Document
>
&
_d
)
:
ZMQMessage
(
_d
)
{};
virtual
Json
::
Value
process
();
string
getSignature
();
};
#endif //SGXWALLET_ECDSASIGNRSPMESSAGE_H
zmq_src/ReqMessage.cpp
View file @
41d00a8f
...
@@ -10,7 +10,7 @@
...
@@ -10,7 +10,7 @@
sgxwallet is distributed in the hope that it will be useful,
sgxwallet is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
You should have received a copy of the GNU Affero General Public License
...
@@ -31,6 +31,9 @@ Json::Value ECDSASignReqMessage::process() {
...
@@ -31,6 +31,9 @@ Json::Value ECDSASignReqMessage::process() {
auto
base
=
getInt64Rapid
(
"base"
);
auto
base
=
getInt64Rapid
(
"base"
);
auto
keyName
=
getStringRapid
(
"keyName"
);
auto
keyName
=
getStringRapid
(
"keyName"
);
auto
hash
=
getStringRapid
(
"messageHash"
);
auto
hash
=
getStringRapid
(
"messageHash"
);
if
(
checkKeyOwnership
&&
!
isKeyByOwner
(
keyName
,
getStringRapid
(
"cert"
)))
{
throw
std
::
invalid_argument
(
"Only owner of the key can access it"
);
}
auto
result
=
SGXWalletServer
::
ecdsaSignMessageHashImpl
(
base
,
keyName
,
hash
);
auto
result
=
SGXWalletServer
::
ecdsaSignMessageHashImpl
(
base
,
keyName
,
hash
);
result
[
"type"
]
=
ZMQMessage
::
ECDSA_SIGN_RSP
;
result
[
"type"
]
=
ZMQMessage
::
ECDSA_SIGN_RSP
;
return
result
;
return
result
;
...
@@ -41,6 +44,9 @@ Json::Value BLSSignReqMessage::process() {
...
@@ -41,6 +44,9 @@ Json::Value BLSSignReqMessage::process() {
auto
hash
=
getStringRapid
(
"messageHash"
);
auto
hash
=
getStringRapid
(
"messageHash"
);
auto
t
=
getInt64Rapid
(
"t"
);
auto
t
=
getInt64Rapid
(
"t"
);
auto
n
=
getInt64Rapid
(
"n"
);
auto
n
=
getInt64Rapid
(
"n"
);
if
(
checkKeyOwnership
&&
!
isKeyByOwner
(
keyName
,
getStringRapid
(
"cert"
)))
{
throw
std
::
invalid_argument
(
"Only owner of the key can access it"
);
}
auto
result
=
SGXWalletServer
::
blsSignMessageHashImpl
(
keyName
,
hash
,
t
,
n
);
auto
result
=
SGXWalletServer
::
blsSignMessageHashImpl
(
keyName
,
hash
,
t
,
n
);
result
[
"type"
]
=
ZMQMessage
::
BLS_SIGN_RSP
;
result
[
"type"
]
=
ZMQMessage
::
BLS_SIGN_RSP
;
return
result
;
return
result
;
...
@@ -50,6 +56,10 @@ Json::Value importBLSReqMessage::process() {
...
@@ -50,6 +56,10 @@ Json::Value importBLSReqMessage::process() {
auto
keyName
=
getStringRapid
(
"keyShareName"
);
auto
keyName
=
getStringRapid
(
"keyShareName"
);
auto
keyShare
=
getStringRapid
(
"keyShare"
);
auto
keyShare
=
getStringRapid
(
"keyShare"
);
auto
result
=
SGXWalletServer
::
importBLSKeyShareImpl
(
keyShare
,
keyName
);
auto
result
=
SGXWalletServer
::
importBLSKeyShareImpl
(
keyShare
,
keyName
);
if
(
checkKeyOwnership
&&
result
[
"status"
]
==
0
)
{
auto
cert
=
getStringRapid
(
"cert"
);
addKeyByOwner
(
keyName
,
cert
);
}
result
[
"type"
]
=
ZMQMessage
::
IMPORT_BLS_RSP
;
result
[
"type"
]
=
ZMQMessage
::
IMPORT_BLS_RSP
;
return
result
;
return
result
;
}
}
...
@@ -58,18 +68,30 @@ Json::Value importECDSAReqMessage::process() {
...
@@ -58,18 +68,30 @@ Json::Value importECDSAReqMessage::process() {
auto
keyName
=
getStringRapid
(
"keyName"
);
auto
keyName
=
getStringRapid
(
"keyName"
);
auto
key
=
getStringRapid
(
"key"
);
auto
key
=
getStringRapid
(
"key"
);
auto
result
=
SGXWalletServer
::
importECDSAKeyImpl
(
key
,
keyName
);
auto
result
=
SGXWalletServer
::
importECDSAKeyImpl
(
key
,
keyName
);
if
(
checkKeyOwnership
&&
result
[
"status"
]
==
0
)
{
auto
cert
=
getStringRapid
(
"cert"
);
addKeyByOwner
(
keyName
,
cert
);
}
result
[
"type"
]
=
ZMQMessage
::
IMPORT_ECDSA_RSP
;
result
[
"type"
]
=
ZMQMessage
::
IMPORT_ECDSA_RSP
;
return
result
;
return
result
;
}
}
Json
::
Value
generateECDSAReqMessage
::
process
()
{
Json
::
Value
generateECDSAReqMessage
::
process
()
{
auto
result
=
SGXWalletServer
::
generateECDSAKeyImpl
();
auto
result
=
SGXWalletServer
::
generateECDSAKeyImpl
();
string
keyName
=
result
[
"keyName"
].
asString
();
if
(
checkKeyOwnership
&&
result
[
"status"
]
==
0
)
{
auto
cert
=
getStringRapid
(
"cert"
);
addKeyByOwner
(
keyName
,
cert
);
}
result
[
"type"
]
=
ZMQMessage
::
GENERATE_ECDSA_RSP
;
result
[
"type"
]
=
ZMQMessage
::
GENERATE_ECDSA_RSP
;
return
result
;
return
result
;
}
}
Json
::
Value
getPublicECDSAReqMessage
::
process
()
{
Json
::
Value
getPublicECDSAReqMessage
::
process
()
{
auto
keyName
=
getStringRapid
(
"keyName"
);
auto
keyName
=
getStringRapid
(
"keyName"
);
if
(
checkKeyOwnership
&&
!
isKeyByOwner
(
keyName
,
getStringRapid
(
"cert"
)))
{
throw
std
::
invalid_argument
(
"Only owner of the key can access it"
);
}
auto
result
=
SGXWalletServer
::
getPublicECDSAKeyImpl
(
keyName
);
auto
result
=
SGXWalletServer
::
getPublicECDSAKeyImpl
(
keyName
);
result
[
"type"
]
=
ZMQMessage
::
GET_PUBLIC_ECDSA_RSP
;
result
[
"type"
]
=
ZMQMessage
::
GET_PUBLIC_ECDSA_RSP
;
return
result
;
return
result
;
...
@@ -79,12 +101,19 @@ Json::Value generateDKGPolyReqMessage::process() {
...
@@ -79,12 +101,19 @@ Json::Value generateDKGPolyReqMessage::process() {
auto
polyName
=
getStringRapid
(
"polyName"
);
auto
polyName
=
getStringRapid
(
"polyName"
);
auto
t
=
getInt64Rapid
(
"t"
);
auto
t
=
getInt64Rapid
(
"t"
);
auto
result
=
SGXWalletServer
::
generateDKGPolyImpl
(
polyName
,
t
);
auto
result
=
SGXWalletServer
::
generateDKGPolyImpl
(
polyName
,
t
);
if
(
checkKeyOwnership
&&
result
[
"status"
]
==
0
)
{
auto
cert
=
getStringRapid
(
"cert"
);
addKeyByOwner
(
polyName
,
cert
);
}
result
[
"type"
]
=
ZMQMessage
::
GENERATE_DKG_POLY_RSP
;
result
[
"type"
]
=
ZMQMessage
::
GENERATE_DKG_POLY_RSP
;
return
result
;
return
result
;
}
}
Json
::
Value
getVerificationVectorReqMessage
::
process
()
{
Json
::
Value
getVerificationVectorReqMessage
::
process
()
{
auto
polyName
=
getStringRapid
(
"polyName"
);
auto
polyName
=
getStringRapid
(
"polyName"
);
if
(
checkKeyOwnership
&&
!
isKeyByOwner
(
polyName
,
getStringRapid
(
"cert"
)))
{
throw
std
::
invalid_argument
(
"Only owner of the key can access it"
);
}
auto
t
=
getInt64Rapid
(
"t"
);
auto
t
=
getInt64Rapid
(
"t"
);
auto
result
=
SGXWalletServer
::
getVerificationVectorImpl
(
polyName
,
t
);
auto
result
=
SGXWalletServer
::
getVerificationVectorImpl
(
polyName
,
t
);
result
[
"type"
]
=
ZMQMessage
::
GET_VV_RSP
;
result
[
"type"
]
=
ZMQMessage
::
GET_VV_RSP
;
...
@@ -96,6 +125,9 @@ Json::Value getSecretShareReqMessage::process() {
...
@@ -96,6 +125,9 @@ Json::Value getSecretShareReqMessage::process() {
auto
t
=
getInt64Rapid
(
"t"
);
auto
t
=
getInt64Rapid
(
"t"
);
auto
n
=
getInt64Rapid
(
"n"
);
auto
n
=
getInt64Rapid
(
"n"
);
auto
pubKeys
=
getJsonValueRapid
(
"publicKeys"
);
auto
pubKeys
=
getJsonValueRapid
(
"publicKeys"
);
if
(
checkKeyOwnership
&&
!
isKeyByOwner
(
polyName
,
getStringRapid
(
"cert"
)))
{
throw
std
::
invalid_argument
(
"Only owner of the key can access it"
);
}
auto
result
=
SGXWalletServer
::
getSecretShareV2Impl
(
polyName
,
pubKeys
,
t
,
n
);
auto
result
=
SGXWalletServer
::
getSecretShareV2Impl
(
polyName
,
pubKeys
,
t
,
n
);
result
[
"type"
]
=
ZMQMessage
::
GET_SECRET_SHARE_RSP
;
result
[
"type"
]
=
ZMQMessage
::
GET_SECRET_SHARE_RSP
;
return
result
;
return
result
;
...
@@ -108,6 +140,9 @@ Json::Value dkgVerificationReqMessage::process() {
...
@@ -108,6 +140,9 @@ Json::Value dkgVerificationReqMessage::process() {
auto
idx
=
getInt64Rapid
(
"index"
);
auto
idx
=
getInt64Rapid
(
"index"
);
auto
pubShares
=
getStringRapid
(
"publicShares"
);
auto
pubShares
=
getStringRapid
(
"publicShares"
);
auto
secretShare
=
getStringRapid
(
"secretShare"
);
auto
secretShare
=
getStringRapid
(
"secretShare"
);
if
(
checkKeyOwnership
&&
!
isKeyByOwner
(
ethKeyName
,
getStringRapid
(
"cert"
)))
{
throw
std
::
invalid_argument
(
"Only owner of the key can access it"
);
}
auto
result
=
SGXWalletServer
::
dkgVerificationV2Impl
(
pubShares
,
ethKeyName
,
secretShare
,
t
,
n
,
idx
);
auto
result
=
SGXWalletServer
::
dkgVerificationV2Impl
(
pubShares
,
ethKeyName
,
secretShare
,
t
,
n
,
idx
);
result
[
"type"
]
=
ZMQMessage
::
DKG_VERIFY_RSP
;
result
[
"type"
]
=
ZMQMessage
::
DKG_VERIFY_RSP
;
return
result
;
return
result
;
...
@@ -120,13 +155,22 @@ Json::Value createBLSPrivateKeyReqMessage::process() {
...
@@ -120,13 +155,22 @@ Json::Value createBLSPrivateKeyReqMessage::process() {
auto
secretShare
=
getStringRapid
(
"secretShare"
);
auto
secretShare
=
getStringRapid
(
"secretShare"
);
auto
t
=
getInt64Rapid
(
"t"
);
auto
t
=
getInt64Rapid
(
"t"
);
auto
n
=
getInt64Rapid
(
"n"
);
auto
n
=
getInt64Rapid
(
"n"
);
if
(
checkKeyOwnership
&&
(
!
isKeyByOwner
(
ethKeyName
,
getStringRapid
(
"cert"
))
||
!
isKeyByOwner
(
polyName
,
getStringRapid
(
"cert"
))))
{
throw
std
::
invalid_argument
(
"Only owner of the key can access it"
);
}
auto
result
=
SGXWalletServer
::
createBLSPrivateKeyV2Impl
(
blsKeyName
,
ethKeyName
,
polyName
,
secretShare
,
t
,
n
);
auto
result
=
SGXWalletServer
::
createBLSPrivateKeyV2Impl
(
blsKeyName
,
ethKeyName
,
polyName
,
secretShare
,
t
,
n
);
if
(
checkKeyOwnership
&&
result
[
"status"
]
==
0
)
{
addKeyByOwner
(
blsKeyName
,
getStringRapid
(
"cert"
));
}
result
[
"type"
]
=
ZMQMessage
::
CREATE_BLS_PRIVATE_RSP
;
result
[
"type"
]
=
ZMQMessage
::
CREATE_BLS_PRIVATE_RSP
;
return
result
;
return
result
;
}
}
Json
::
Value
getBLSPublicReqMessage
::
process
()
{
Json
::
Value
getBLSPublicReqMessage
::
process
()
{
auto
blsKeyName
=
getStringRapid
(
"blsKeyName"
);
auto
blsKeyName
=
getStringRapid
(
"blsKeyName"
);
if
(
checkKeyOwnership
&&
!
isKeyByOwner
(
blsKeyName
,
getStringRapid
(
"cert"
)))
{
throw
std
::
invalid_argument
(
"Only owner of the key can access it"
);
}
auto
result
=
SGXWalletServer
::
getBLSPublicKeyShareImpl
(
blsKeyName
);
auto
result
=
SGXWalletServer
::
getBLSPublicKeyShareImpl
(
blsKeyName
);
result
[
"type"
]
=
ZMQMessage
::
GET_BLS_PUBLIC_RSP
;
result
[
"type"
]
=
ZMQMessage
::
GET_BLS_PUBLIC_RSP
;
return
result
;
return
result
;
...
@@ -146,6 +190,9 @@ Json::Value complaintResponseReqMessage::process() {
...
@@ -146,6 +190,9 @@ Json::Value complaintResponseReqMessage::process() {
auto
t
=
getInt64Rapid
(
"t"
);
auto
t
=
getInt64Rapid
(
"t"
);
auto
n
=
getInt64Rapid
(
"n"
);
auto
n
=
getInt64Rapid
(
"n"
);
auto
idx
=
getInt64Rapid
(
"ind"
);
auto
idx
=
getInt64Rapid
(
"ind"
);
if
(
checkKeyOwnership
&&
!
isKeyByOwner
(
polyName
,
getStringRapid
(
"cert"
)))
{
throw
std
::
invalid_argument
(
"Only owner of the key can access it"
);
}
auto
result
=
SGXWalletServer
::
complaintResponseImpl
(
polyName
,
t
,
n
,
idx
);
auto
result
=
SGXWalletServer
::
complaintResponseImpl
(
polyName
,
t
,
n
,
idx
);
result
[
"type"
]
=
ZMQMessage
::
COMPLAINT_RESPONSE_RSP
;
result
[
"type"
]
=
ZMQMessage
::
COMPLAINT_RESPONSE_RSP
;
return
result
;
return
result
;
...
@@ -179,6 +226,9 @@ Json::Value getServerVersionReqMessage::process() {
...
@@ -179,6 +226,9 @@ Json::Value getServerVersionReqMessage::process() {
Json
::
Value
deleteBLSKeyReqMessage
::
process
()
{
Json
::
Value
deleteBLSKeyReqMessage
::
process
()
{
auto
blsKeyName
=
getStringRapid
(
"blsKeyName"
);
auto
blsKeyName
=
getStringRapid
(
"blsKeyName"
);
if
(
checkKeyOwnership
&&
!
isKeyByOwner
(
blsKeyName
,
getStringRapid
(
"cert"
)))
{
throw
std
::
invalid_argument
(
"Only owner of the key can access it"
);
}
auto
result
=
SGXWalletServer
::
deleteBlsKeyImpl
(
blsKeyName
);
auto
result
=
SGXWalletServer
::
deleteBlsKeyImpl
(
blsKeyName
);
result
[
"type"
]
=
ZMQMessage
::
DELETE_BLS_KEY_RSP
;
result
[
"type"
]
=
ZMQMessage
::
DELETE_BLS_KEY_RSP
;
return
result
;
return
result
;
...
...
zmq_src/ZMQClient.cpp
View file @
41d00a8f
...
@@ -67,7 +67,7 @@ shared_ptr <ZMQMessage> ZMQClient::doRequestReply(Json::Value &_req) {
...
@@ -67,7 +67,7 @@ shared_ptr <ZMQMessage> ZMQClient::doRequestReply(Json::Value &_req) {
CHECK_STATE
(
resultStr
.
front
()
==
'{'
)
CHECK_STATE
(
resultStr
.
front
()
==
'{'
)
CHECK_STATE
(
resultStr
.
back
()
==
'}'
)
CHECK_STATE
(
resultStr
.
back
()
==
'}'
)
return
ZMQMessage
::
parse
(
resultStr
.
c_str
(),
resultStr
.
size
(),
false
,
false
);
return
ZMQMessage
::
parse
(
resultStr
.
c_str
(),
resultStr
.
size
(),
false
,
false
,
false
);
}
catch
(
std
::
exception
&
e
)
{
}
catch
(
std
::
exception
&
e
)
{
spdlog
::
error
(
string
(
"Error in doRequestReply:"
)
+
e
.
what
());
spdlog
::
error
(
string
(
"Error in doRequestReply:"
)
+
e
.
what
());
throw
;
throw
;
...
...
zmq_src/ZMQMessage.cpp
View file @
41d00a8f
...
@@ -28,6 +28,7 @@
...
@@ -28,6 +28,7 @@
#include <fstream>
#include <fstream>
#include "ZMQClient.h"
#include "ZMQClient.h"
#include "LevelDB.h"
#include "SGXWalletServer.hpp"
#include "SGXWalletServer.hpp"
#include "ReqMessage.h"
#include "ReqMessage.h"
#include "RspMessage.h"
#include "RspMessage.h"
...
@@ -75,7 +76,7 @@ string ZMQMessage::getStringRapid(const char *_name) {
...
@@ -75,7 +76,7 @@ string ZMQMessage::getStringRapid(const char *_name) {
shared_ptr
<
ZMQMessage
>
ZMQMessage
::
parse
(
const
char
*
_msg
,
shared_ptr
<
ZMQMessage
>
ZMQMessage
::
parse
(
const
char
*
_msg
,
size_t
_size
,
bool
_isRequest
,
size_t
_size
,
bool
_isRequest
,
bool
_verifySig
)
{
bool
_verifySig
,
bool
_checkKeyOwnership
)
{
CHECK_STATE
(
_msg
);
CHECK_STATE
(
_msg
);
CHECK_STATE2
(
_size
>
5
,
ZMQ_INVALID_MESSAGE_SIZE
);
CHECK_STATE2
(
_size
>
5
,
ZMQ_INVALID_MESSAGE_SIZE
);
...
@@ -149,16 +150,15 @@ shared_ptr <ZMQMessage> ZMQMessage::parse(const char *_msg,
...
@@ -149,16 +150,15 @@ shared_ptr <ZMQMessage> ZMQMessage::parse(const char *_msg,
}
}
}
}
shared_ptr
<
ZMQMessage
>
result
;
if
(
_isRequest
)
{
if
(
_isRequest
)
{
return
buildRequest
(
type
,
d
);
return
buildRequest
(
type
,
d
,
_checkKeyOwnership
);
}
else
{
}
else
{
return
buildResponse
(
type
,
d
);
return
buildResponse
(
type
,
d
,
_checkKeyOwnership
);
}
}
}
}
shared_ptr
<
ZMQMessage
>
ZMQMessage
::
buildRequest
(
string
&
_type
,
shared_ptr
<
rapidjson
::
Document
>
_d
)
{
shared_ptr
<
ZMQMessage
>
ZMQMessage
::
buildRequest
(
string
&
_type
,
shared_ptr
<
rapidjson
::
Document
>
_d
,
bool
_checkKeyOwnership
)
{
Requests
r
;
Requests
r
;
try
{
try
{
int
t
=
requests
.
at
(
_type
);
int
t
=
requests
.
at
(
_type
);
...
@@ -231,10 +231,13 @@ shared_ptr <ZMQMessage> ZMQMessage::buildRequest(string &_type, shared_ptr <rapi
...
@@ -231,10 +231,13 @@ shared_ptr <ZMQMessage> ZMQMessage::buildRequest(string &_type, shared_ptr <rapi
break
;
break
;
}
}
ret
->
setCheckKeyOwnership
(
_checkKeyOwnership
);
return
ret
;
return
ret
;
}
}
shared_ptr
<
ZMQMessage
>
ZMQMessage
::
buildResponse
(
string
&
_type
,
shared_ptr
<
rapidjson
::
Document
>
_d
)
{
shared_ptr
<
ZMQMessage
>
ZMQMessage
::
buildResponse
(
string
&
_type
,
shared_ptr
<
rapidjson
::
Document
>
_d
,
bool
_checkKeyOwnership
)
{
Responses
r
;
Responses
r
;
try
{
try
{
int
t
=
responses
.
at
(
_type
);
int
t
=
responses
.
at
(
_type
);
...
@@ -309,9 +312,22 @@ shared_ptr <ZMQMessage> ZMQMessage::buildResponse(string &_type, shared_ptr <rap
...
@@ -309,9 +312,22 @@ shared_ptr <ZMQMessage> ZMQMessage::buildResponse(string &_type, shared_ptr <rap
break
;
break
;
}
}
ret
->
setCheckKeyOwnership
(
_checkKeyOwnership
);
return
ret
;
return
ret
;
}
}
std
::
map
<
string
,
string
>
ZMQMessage
::
keysByOwners
;
bool
ZMQMessage
::
isKeyByOwner
(
const
string
&
keyName
,
const
string
&
cert
)
{
auto
value
=
LevelDB
::
getLevelDb
()
->
readString
(
keyName
);
return
value
&&
*
value
==
cert
;
}
void
ZMQMessage
::
addKeyByOwner
(
const
string
&
keyName
,
const
string
&
cert
)
{
SGXWalletServer
::
writeDataToDB
(
keyName
,
cert
);
}
cache
::
lru_cache
<
string
,
pair
<
EVP_PKEY
*
,
X509
*>>
ZMQMessage
::
verifiedCerts
(
256
);
cache
::
lru_cache
<
string
,
pair
<
EVP_PKEY
*
,
X509
*>>
ZMQMessage
::
verifiedCerts
(
256
);
const
std
::
map
<
string
,
int
>
ZMQMessage
::
requests
{
const
std
::
map
<
string
,
int
>
ZMQMessage
::
requests
{
...
...
zmq_src/ZMQMessage.h
View file @
41d00a8f
...
@@ -51,6 +51,15 @@ class ZMQMessage {
...
@@ -51,6 +51,15 @@ class ZMQMessage {
static
cache
::
lru_cache
<
string
,
pair
<
EVP_PKEY
*
,
X509
*>>
verifiedCerts
;
static
cache
::
lru_cache
<
string
,
pair
<
EVP_PKEY
*
,
X509
*>>
verifiedCerts
;
protected
:
bool
checkKeyOwnership
=
true
;
static
std
::
map
<
string
,
string
>
keysByOwners
;
static
bool
isKeyByOwner
(
const
string
&
keyName
,
const
string
&
cert
);
static
void
addKeyByOwner
(
const
string
&
keyName
,
const
string
&
cert
);
public
:
public
:
static
constexpr
const
char
*
BLS_SIGN_REQ
=
"BLSSignReq"
;
static
constexpr
const
char
*
BLS_SIGN_REQ
=
"BLSSignReq"
;
...
@@ -127,11 +136,15 @@ public:
...
@@ -127,11 +136,15 @@ public:
}
}
static
shared_ptr
<
ZMQMessage
>
parse
(
const
char
*
_msg
,
size_t
_size
,
bool
_isRequest
,
static
shared_ptr
<
ZMQMessage
>
parse
(
const
char
*
_msg
,
size_t
_size
,
bool
_isRequest
,
bool
_verifySig
);
bool
_verifySig
,
bool
_checkKeyOwnership
);
static
shared_ptr
<
ZMQMessage
>
buildRequest
(
string
&
type
,
shared_ptr
<
rapidjson
::
Document
>
_d
);
static
shared_ptr
<
ZMQMessage
>
buildRequest
(
string
&
type
,
shared_ptr
<
rapidjson
::
Document
>
_d
,
static
shared_ptr
<
ZMQMessage
>
buildResponse
(
string
&
type
,
shared_ptr
<
rapidjson
::
Document
>
_d
);
bool
_checkKeyOwnership
);
static
shared_ptr
<
ZMQMessage
>
buildResponse
(
string
&
type
,
shared_ptr
<
rapidjson
::
Document
>
_d
,
bool
_checkKeyOwnership
);
virtual
Json
::
Value
process
()
=
0
;
virtual
Json
::
Value
process
()
=
0
;
void
setCheckKeyOwnership
(
bool
_check
)
{
checkKeyOwnership
=
_check
;
}
};
};
zmq_src/ZMQServer.cpp
View file @
41d00a8f
...
@@ -38,8 +38,8 @@ using namespace std;
...
@@ -38,8 +38,8 @@ using namespace std;
shared_ptr
<
ZMQServer
>
ZMQServer
::
zmqServer
=
nullptr
;
shared_ptr
<
ZMQServer
>
ZMQServer
::
zmqServer
=
nullptr
;
ZMQServer
::
ZMQServer
(
bool
_checkSignature
,
const
string
&
_caCertFile
)
ZMQServer
::
ZMQServer
(
bool
_checkSignature
,
bool
_checkKeyOwnership
,
const
string
&
_caCertFile
)
:
checkSignature
(
_checkSignature
),
:
checkSignature
(
_checkSignature
),
checkKeyOwnership
(
_checkKeyOwnership
),
caCertFile
(
_caCertFile
),
ctx
(
make_shared
<
zmq
::
context_t
>
(
1
))
{
caCertFile
(
_caCertFile
),
ctx
(
make_shared
<
zmq
::
context_t
>
(
1
))
{
socket
=
make_shared
<
zmq
::
socket_t
>
(
*
ctx
,
ZMQ_ROUTER
);
socket
=
make_shared
<
zmq
::
socket_t
>
(
*
ctx
,
ZMQ_ROUTER
);
...
@@ -94,12 +94,13 @@ void ZMQServer::exitZMQServer() {
...
@@ -94,12 +94,13 @@ void ZMQServer::exitZMQServer() {
spdlog
::
info
(
"Exited zmq server."
);
spdlog
::
info
(
"Exited zmq server."
);
}
}
void
ZMQServer
::
initZMQServer
(
bool
_checkSignature
)
{
void
ZMQServer
::
initZMQServer
(
bool
_checkSignature
,
bool
_checkKeyOwnership
)
{
static
bool
initedServer
=
false
;
static
bool
initedServer
=
false
;
CHECK_STATE
(
!
initedServer
)
CHECK_STATE
(
!
initedServer
)
initedServer
=
true
;
initedServer
=
true
;
spdlog
::
info
(
"Initing zmq server. checkSignature is set to {}"
,
_checkSignature
);
spdlog
::
info
(
"Initing zmq server.
\n
checkSignature is set to {}.
\n
checkKeyOwnership is set to {}"
,
_checkSignature
,
_checkKeyOwnership
);
string
rootCAPath
=
""
;
string
rootCAPath
=
""
;
...
@@ -109,7 +110,7 @@ void ZMQServer::initZMQServer(bool _checkSignature) {
...
@@ -109,7 +110,7 @@ void ZMQServer::initZMQServer(bool _checkSignature) {
CHECK_STATE
(
access
(
rootCAPath
.
c_str
(),
F_OK
)
==
0
);
CHECK_STATE
(
access
(
rootCAPath
.
c_str
(),
F_OK
)
==
0
);
};
};
zmqServer
=
make_shared
<
ZMQServer
>
(
_checkSignature
,
rootCAPath
);
zmqServer
=
make_shared
<
ZMQServer
>
(
_checkSignature
,
_checkKeyOwnership
,
rootCAPath
);
CHECK_STATE
(
zmqServer
)
CHECK_STATE
(
zmqServer
)
...
@@ -179,7 +180,7 @@ void ZMQServer::doOneServerLoop() {
...
@@ -179,7 +180,7 @@ void ZMQServer::doOneServerLoop() {
CHECK_STATE
(
stringToParse
.
back
()
==
'}'
)
CHECK_STATE
(
stringToParse
.
back
()
==
'}'
)
auto
parsedMsg
=
ZMQMessage
::
parse
(
auto
parsedMsg
=
ZMQMessage
::
parse
(
stringToParse
.
c_str
(),
stringToParse
.
size
(),
true
,
checkSignature
);
stringToParse
.
c_str
(),
stringToParse
.
size
(),
true
,
checkSignature
,
checkKeyOwnership
);
CHECK_STATE2
(
parsedMsg
,
ZMQ_COULD_NOT_PARSE
);
CHECK_STATE2
(
parsedMsg
,
ZMQ_COULD_NOT_PARSE
);
...
...
zmq_src/ZMQServer.h
View file @
41d00a8f
...
@@ -14,7 +14,7 @@
...
@@ -14,7 +14,7 @@
GNU Affero General Public License for more details.
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
You should have received a copy of the GNU Affero General Public License
along with sgxwallet.
If not, see <https://www.gnu.org/licenses/>.
along with sgxwallet. If not, see <https://www.gnu.org/licenses/>.
@file ZMQServer.h
@file ZMQServer.h
@author Stan Kladko
@author Stan Kladko
...
@@ -52,16 +52,18 @@ public:
...
@@ -52,16 +52,18 @@ public:
static
shared_ptr
<
std
::
thread
>
serverThread
;
static
shared_ptr
<
std
::
thread
>
serverThread
;
ZMQServer
(
bool
_checkSignature
,
const
string
&
_caCertFile
);
ZMQServer
(
bool
_checkSignature
,
bool
_checkKeyOwnership
,
const
string
&
_caCertFile
);
~
ZMQServer
();
~
ZMQServer
();
void
run
();
void
run
();
static
void
initZMQServer
(
bool
_checkSignature
);
static
void
initZMQServer
(
bool
_checkSignature
,
bool
_checkKeyOwnership
);
static
void
exitZMQServer
();
static
void
exitZMQServer
();
private
:
private
:
bool
checkKeyOwnership
=
true
;
shared_ptr
<
zmq
::
context_t
>
ctx
;
shared_ptr
<
zmq
::
context_t
>
ctx
;
shared_ptr
<
zmq
::
socket_t
>
socket
;
shared_ptr
<
zmq
::
socket_t
>
socket
;
...
...
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