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
0ee16cca
Unverified
Commit
0ee16cca
authored
Apr 01, 2021
by
Oleh Nikolaiev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-4005 add unique exit codes
parent
75ee6f0d
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
35 additions
and
46 deletions
+35
-46
CSRManagerServer.cpp
CSRManagerServer.cpp
+1
-1
ExitHandler.h
ExitHandler.h
+6
-4
LevelDB.cpp
LevelDB.cpp
+2
-2
SEKManager.cpp
SEKManager.cpp
+5
-5
SGXInfoServer.cpp
SGXInfoServer.cpp
+1
-1
SGXRegistrationServer.cpp
SGXRegistrationServer.cpp
+1
-1
SGXWalletServer.cpp
SGXWalletServer.cpp
+5
-9
ServerInit.cpp
ServerInit.cpp
+7
-7
sgxwall.cpp
sgxwall.cpp
+7
-15
sgxwall.h
sgxwall.h
+0
-1
No files found.
CSRManagerServer.cpp
View file @
0ee16cca
...
...
@@ -120,7 +120,7 @@ int CSRManagerServer::initCSRManagerServer() {
if
(
!
cs
->
StartListening
())
{
spdlog
::
info
(
"CSR manager server could not start listening"
);
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
failure
);
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
error_starting_server
);
exit
(
-
1
);
}
else
{
spdlog
::
info
(
"CSR manager server started on port {}"
,
BASE_PORT
+
2
);
...
...
ExitHandler.h
View file @
0ee16cca
...
...
@@ -11,11 +11,13 @@ public:
ec_success
=
0
,
ec_failure
=
1
,
// same as EXIT_FAILURE in stdlib.h, generic failure in main()
ec_termninated_by_signal
=
196
,
ec_
compute_snapshot_error
=
197
,
// snapshot computation error
ec_
error_starting_server
=
197
,
// error starting one of the http(s) servers
ec_rotation_complete
=
0
,
// must be zero, exit requested after rotation complete
ec_consensus_terminate_request
=
198
,
// exit requested by consensus
ec_web3_request
=
199
,
// programmatic shutdown via Web3 call, when enabled
ec_state_root_mismatch
=
200
,
// current state root is not equal to arrived from consensus
ec_error_creating_database
=
198
,
// error initing LevelDB
ec_error_initing_sek
=
199
,
// error while initing or validating SEK
ec_creating_certificate
=
200
,
// error creating SSL certificate to initialize server
ec_initing_enclave
=
201
,
// error starting secure enclave
ec_initing_user_space
=
202
,
// error or exception while initializing user space
};
private
:
...
...
LevelDB.cpp
View file @
0ee16cca
...
...
@@ -276,7 +276,7 @@ void LevelDB::initDataFolderAndDBs() {
if
(
getcwd
(
cwd
,
sizeof
(
cwd
))
==
NULL
)
{
spdlog
::
error
(
"could not get current workin directory"
);
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
failur
e
);
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
error_creating_databas
e
);
exit
(
-
2
);
}
...
...
@@ -291,7 +291,7 @@ void LevelDB::initDataFolderAndDBs() {
}
else
{
spdlog
::
error
(
"Couldnt create creating sgx_data folder"
);
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
failur
e
);
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
error_creating_databas
e
);
exit
(
-
3
);
}
}
...
...
SEKManager.cpp
View file @
0ee16cca
...
...
@@ -91,7 +91,7 @@ void validate_SEK() {
if
(
!
hex2carray
(
test_key_ptr
->
c_str
(),
&
len
,
encr_test_key
.
data
(),
BUF_LEN
))
{
spdlog
::
error
(
"Corrupt test key is LevelDB"
);
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
failure
);
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
error_initing_sek
);
exit
(
-
4
);
}
...
...
@@ -110,7 +110,7 @@ void validate_SEK() {
spdlog
::
error
(
"Invalid storage key. You need to recover using backup key"
);
spdlog
::
error
(
"Set the correct backup key into sgx_datasgxwallet_backup_key.txt"
);
spdlog
::
error
(
"Then run sgxwallet using backup flag"
);
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
failure
);
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
error_initing_sek
);
exit
(
-
5
);
}
}
...
...
@@ -259,14 +259,14 @@ void enter_SEK() {
shared_ptr
<
string
>
test_key_ptr
=
LevelDB
::
getLevelDb
()
->
readString
(
"TEST_KEY"
);
if
(
test_key_ptr
==
nullptr
)
{
spdlog
::
error
(
"Error: corrupt or empty LevelDB database"
);
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
failure
);
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
error_initing_sek
);
exit
(
-
7
);
}
if
(
!
experimental
::
filesystem
::
is_regular_file
(
BACKUP_PATH
))
{
spdlog
::
error
(
"File does not exist: "
BACKUP_PATH
);
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
failure
);
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
error_initing_sek
);
exit
(
-
8
);
}
...
...
@@ -283,7 +283,7 @@ void enter_SEK() {
while
(
!
checkHex
(
sek
,
16
))
{
spdlog
::
error
(
"Invalid hex in key"
);
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
failure
);
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
error_initing_sek
);
exit
(
-
9
);
}
...
...
SGXInfoServer.cpp
View file @
0ee16cca
...
...
@@ -116,7 +116,7 @@ int SGXInfoServer::initInfoServer(uint32_t _logLevel, bool _autoSign, bool _chec
if
(
!
server
->
StartListening
())
{
spdlog
::
error
(
"Info server could not start listening on port {}"
,
BASE_PORT
+
4
);
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
failure
);
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
error_starting_server
);
exit
(
-
10
);
}
else
{
spdlog
::
info
(
"Info server started on port {}"
,
BASE_PORT
+
4
);
...
...
SGXRegistrationServer.cpp
View file @
0ee16cca
...
...
@@ -173,7 +173,7 @@ int SGXRegistrationServer::initRegistrationServer(bool _autoSign) {
if
(
!
server
->
StartListening
())
{
spdlog
::
error
(
"Registration server could not start listening on port {}"
,
BASE_PORT
+
1
);
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
failure
);
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
error_starting_server
);
exit
(
-
10
);
}
else
{
spdlog
::
info
(
"Registration server started on port {}"
,
BASE_PORT
+
1
);
...
...
SGXWalletServer.cpp
View file @
0ee16cca
...
...
@@ -142,7 +142,7 @@ void SGXWalletServer::createCertsIfNeeded() {
spdlog
::
info
(
"ROOT CA CERTIFICATE IS SUCCESSFULLY GENERATED"
);
}
else
{
spdlog
::
error
(
"ROOT CA CERTIFICATE GENERATION FAILED"
);
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
failur
e
);
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
creating_certificat
e
);
exit
(
-
11
);
}
}
...
...
@@ -160,7 +160,7 @@ void SGXWalletServer::createCertsIfNeeded() {
spdlog
::
info
(
"SERVER CERTIFICATE IS SUCCESSFULLY GENERATED"
);
}
else
{
spdlog
::
info
(
"SERVER CERTIFICATE GENERATION FAILED"
);
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
failur
e
);
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
creating_certificat
e
);
exit
(
-
12
);
}
}
...
...
@@ -171,7 +171,7 @@ void SGXWalletServer::createCertsIfNeeded() {
spdlog
::
info
(
"SERVER CERTIFICATE IS SUCCESSFULLY VERIFIED"
);
}
else
{
spdlog
::
info
(
"SERVER CERTIFICATE VERIFICATION FAILED"
);
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
failur
e
);
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
creating_certificat
e
);
exit
(
-
12
);
}
}
...
...
@@ -182,10 +182,6 @@ int SGXWalletServer::initHttpsServer(bool _checkCerts) {
spdlog
::
info
(
"Entering {}"
,
__FUNCTION__
);
spdlog
::
info
(
"Initing server, number of threads: {}"
,
NUM_THREADS
);
string
certPath
=
string
(
SGXDATA_FOLDER
)
+
"cert_data/SGXServerCert.crt"
;
string
keyPath
=
string
(
SGXDATA_FOLDER
)
+
"cert_data/SGXServerCert.key"
;
string
rootCAPath
=
string
(
SGXDATA_FOLDER
)
+
"cert_data/rootCA.pem"
;
...
...
@@ -201,7 +197,7 @@ int SGXWalletServer::initHttpsServer(bool _checkCerts) {
if
(
!
server
->
StartListening
())
{
spdlog
::
error
(
"SGX Server could not start listening"
);
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
failure
);
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
error_starting_server
);
exit
(
-
13
);
}
else
{
spdlog
::
info
(
"SGX Server started on port {}"
,
BASE_PORT
);
...
...
@@ -221,7 +217,7 @@ int SGXWalletServer::initHttpServer() { //without ssl
JSONRPC_SERVER_V2
);
// hybrid server (json-rpc 1.0 & 2.0)
if
(
!
server
->
StartListening
())
{
spdlog
::
error
(
"Server could not start listening"
);
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
failure
);
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
error_starting_server
);
exit
(
-
14
);
}
return
0
;
...
...
ServerInit.cpp
View file @
0ee16cca
...
...
@@ -71,7 +71,7 @@ void systemHealthCheck() {
ulimit
=
exec
(
"/bin/bash -c
\"
ulimit -n
\"
"
);
}
catch
(...)
{
spdlog
::
error
(
"Execution of '/bin/bash -c ulimit -n' failed"
);
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
failur
e
);
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
initing_user_spac
e
);
exit
(
-
15
);
}
int
noFiles
=
strtol
(
ulimit
.
c_str
(),
NULL
,
10
);
...
...
@@ -86,7 +86,7 @@ void systemHealthCheck() {
"and setting 'DefaultLimitNOFILE=65535'
\n
"
"After that, restart sgxwallet"
;
spdlog
::
error
(
errStr
);
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
failur
e
);
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
initing_user_spac
e
);
exit
(
-
16
);
}
}
...
...
@@ -119,7 +119,7 @@ uint64_t initEnclave() {
support
=
get_sgx_support
();
if
(
!
SGX_OK
(
support
))
{
sgx_support_perror
(
support
);
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
failur
e
);
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
initing_enclav
e
);
exit
(
-
17
);
}
#endif
...
...
@@ -151,7 +151,7 @@ uint64_t initEnclave() {
}
else
{
spdlog
::
error
(
"sgx_create_enclave_search failed {} {}"
,
ENCLAVE_NAME
,
status
);
}
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
failur
e
);
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
initing_enclav
e
);
exit
(
-
21
);
}
...
...
@@ -227,18 +227,18 @@ void initAll(uint32_t _logLevel, bool _checkCert,
sgxServerInited
=
true
;
}
catch
(
SGXException
&
_e
)
{
spdlog
::
error
(
_e
.
getMessage
());
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
failur
e
);
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
initing_user_spac
e
);
exit
(
-
18
);
}
catch
(
exception
&
_e
)
{
spdlog
::
error
(
_e
.
what
());
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
failur
e
);
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
initing_user_spac
e
);
exit
(
-
19
);
}
catch
(...)
{
exception_ptr
p
=
current_exception
();
printf
(
"Exception %s
\n
"
,
p
.
__cxa_exception_type
()
->
name
());
spdlog
::
error
(
"Unknown exception"
);
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
failur
e
);
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_
initing_user_spac
e
);
exit
(
-
22
);
}
};
...
...
sgxwall.cpp
View file @
0ee16cca
...
...
@@ -42,12 +42,6 @@
#include "sgxwallet.h"
void
SGXWallet
::
usage
()
{
cerr
<<
"usage: sgxwallet
\n
"
;
ExitHandler
::
exitHandler
(
SIGTERM
,
ExitHandler
::
ec_failure
);
exit
(
-
21
);
}
void
SGXWallet
::
printUsage
()
{
cerr
<<
"
\n
Available flags:
\n
"
;
cerr
<<
"
\n
Debug flags:
\n\n
"
;
...
...
@@ -211,16 +205,14 @@ int main(int argc, char *argv[]) {
while
(
true
)
{
while
(
!
ExitHandler
::
shouldExit
()
)
{
sleep
(
10
);
if
(
ExitHandler
::
shouldExit
()
)
{
ExitHandler
::
exit_code_t
exitCode
=
ExitHandler
::
requestedExitCode
();
spdlog
::
info
(
"Will exit with exit code {}"
,
exitCode
);
exitAll
();
spdlog
::
info
(
"Exiting with exit code {}"
,
exitCode
);
return
exitCode
;
}
}
return
0
;
ExitHandler
::
exit_code_t
exitCode
=
ExitHandler
::
requestedExitCode
();
int
signal
=
ExitHandler
::
getSignal
();
spdlog
::
info
(
"Will exit with exit code {}"
,
exitCode
);
exitAll
();
spdlog
::
info
(
"Exiting with exit code {} and signal"
,
exitCode
,
signal
);
return
exitCode
;
}
sgxwall.h
View file @
0ee16cca
...
...
@@ -26,7 +26,6 @@ class SGXWallet {
public
:
static
void
usage
();
static
void
printUsage
();
static
void
serializeKeys
(
const
vector
<
string
>&
_ecdsaKeyNames
,
...
...
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