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
e8c852a6
Unverified
Commit
e8c852a6
authored
Jul 07, 2021
by
Oleh Nikolaiev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-4091 fix multithreading issues for generating certs
parent
b034e149
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
24 deletions
+12
-24
SGXRegistrationServer.cpp
SGXRegistrationServer.cpp
+11
-19
SGXRegistrationServer.h
SGXRegistrationServer.h
+1
-5
No files found.
SGXRegistrationServer.cpp
View file @
e8c852a6
...
...
@@ -59,14 +59,16 @@ SGXRegistrationServer::SGXRegistrationServer(AbstractServerConnector &connector,
:
AbstractRegServer
(
connector
,
type
),
autoSign
(
_autoSign
)
{}
Json
::
Value
signCertificateImpl
(
const
string
&
_csr
,
bool
_autoSign
=
false
)
{
Json
::
Value
SGXRegistrationServer
::
SignCertificate
(
const
string
&
csr
)
{
spdlog
::
info
(
__FUNCTION__
);
INIT_RESULT
(
result
)
result
[
"result"
]
=
false
;
try
{
string
hash
=
cryptlite
::
sha256
::
hash_hex
(
_csr
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
m
);
string
hash
=
cryptlite
::
sha256
::
hash_hex
(
csr
);
if
(
system
(
"ls "
CERT_DIR
"/"
CERT_CREATE_COMMAND
)
!=
0
)
{
spdlog
::
error
(
"cert/create_client_cert does not exist"
);
...
...
@@ -76,7 +78,7 @@ Json::Value signCertificateImpl(const string &_csr, bool _autoSign = false) {
string
csr_name
=
string
(
CERT_DIR
)
+
"/"
+
hash
+
".csr"
;
ofstream
outfile
(
csr_name
);
outfile
.
exceptions
(
std
::
ifstream
::
failbit
|
std
::
ifstream
::
badbit
);
outfile
<<
_
csr
<<
endl
;
outfile
<<
csr
<<
endl
;
outfile
.
close
();
if
(
system
((
"ls "
+
csr_name
).
c_str
())
!=
0
)
{
...
...
@@ -85,11 +87,11 @@ Json::Value signCertificateImpl(const string &_csr, bool _autoSign = false) {
}
if
(
system
((
"openssl req -in "
+
csr_name
).
c_str
())
!=
0
)
{
spdlog
::
error
(
"Incorrect CSR format: {}"
,
_
csr
);
spdlog
::
error
(
"Incorrect CSR format: {}"
,
csr
);
throw
SGXException
(
FAIL_TO_CREATE_CERTIFICATE
,
"Incorrect CSR format "
);
}
if
(
_
autoSign
)
{
if
(
autoSign
)
{
string
genCert
=
string
(
"cd "
)
+
CERT_DIR
+
"&& ./"
+
CERT_CREATE_COMMAND
+
" "
+
hash
;
...
...
@@ -104,7 +106,7 @@ Json::Value signCertificateImpl(const string &_csr, bool _autoSign = false) {
}
}
else
{
string
db_key
=
"CSR:HASH:"
+
hash
;
LevelDB
::
getCsrStatusDb
()
->
writeDataUnique
(
db_key
,
_
csr
);
LevelDB
::
getCsrStatusDb
()
->
writeDataUnique
(
db_key
,
csr
);
}
result
[
"result"
]
=
true
;
...
...
@@ -115,7 +117,9 @@ Json::Value signCertificateImpl(const string &_csr, bool _autoSign = false) {
RETURN_SUCCESS
(
result
)
}
Json
::
Value
getCertificateImpl
(
const
string
&
hash
)
{
Json
::
Value
SGXRegistrationServer
::
GetCertificate
(
const
string
&
hash
)
{
spdlog
::
info
(
__FUNCTION__
);
Json
::
Value
result
;
string
cert
;
...
...
@@ -151,17 +155,6 @@ Json::Value getCertificateImpl(const string &hash) {
}
Json
::
Value
SGXRegistrationServer
::
SignCertificate
(
const
string
&
csr
)
{
spdlog
::
info
(
__FUNCTION__
);
return
signCertificateImpl
(
csr
,
autoSign
);
}
Json
::
Value
SGXRegistrationServer
::
GetCertificate
(
const
string
&
hash
)
{
spdlog
::
info
(
__FUNCTION__
);
return
getCertificateImpl
(
hash
);
}
void
SGXRegistrationServer
::
initRegistrationServer
(
bool
_autoSign
)
{
httpServer
=
make_shared
<
HttpServer
>
(
BASE_PORT
+
1
);
server
=
make_shared
<
SGXRegistrationServer
>
(
*
httpServer
,
...
...
@@ -190,7 +183,6 @@ int SGXRegistrationServer::exitServer() {
return
0
;
}
shared_ptr
<
SGXRegistrationServer
>
SGXRegistrationServer
::
getServer
()
{
CHECK_STATE
(
server
);
return
server
;
...
...
SGXRegistrationServer.h
View file @
e8c852a6
...
...
@@ -39,23 +39,19 @@ using namespace jsonrpc;
using
namespace
std
;
class
SGXRegistrationServer
:
public
AbstractRegServer
{
recursive_
mutex
m
;
mutex
m
;
bool
autoSign
;
static
shared_ptr
<
HttpServer
>
httpServer
;
static
shared_ptr
<
SGXRegistrationServer
>
server
;
public
:
static
shared_ptr
<
SGXRegistrationServer
>
getServer
();
SGXRegistrationServer
(
AbstractServerConnector
&
connector
,
serverVersion_t
type
,
bool
_autoSign
=
false
);
virtual
Json
::
Value
SignCertificate
(
const
string
&
csr
);
virtual
Json
::
Value
GetCertificate
(
const
string
&
hash
);
...
...
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