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
903a6e2b
Unverified
Commit
903a6e2b
authored
Jan 13, 2020
by
svetaro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SKALE-1762 Add error handling
parent
97768b50
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
20 deletions
+53
-20
CSRManagerServer.cpp
CSRManagerServer.cpp
+4
-2
SGXRegistrationServer.cpp
SGXRegistrationServer.cpp
+11
-18
abstractCSRManagerServer.h
abstractCSRManagerServer.h
+38
-0
No files found.
CSRManagerServer.cpp
View file @
903a6e2b
...
@@ -29,9 +29,7 @@ Json::Value GetUnsignedCSRsImpl(){
...
@@ -29,9 +29,7 @@ Json::Value GetUnsignedCSRsImpl(){
try
{
try
{
std
::
vector
<
std
::
string
>
hashes_vect
=
csrDb
->
writeKeysToVector1
(
MAX_CSR_NUM
);
std
::
vector
<
std
::
string
>
hashes_vect
=
csrDb
->
writeKeysToVector1
(
MAX_CSR_NUM
);
//std::cerr << " vector size is " << hashes_vect.size() << std::endl;
for
(
int
i
=
0
;
i
<
hashes_vect
.
size
();
i
++
){
for
(
int
i
=
0
;
i
<
hashes_vect
.
size
();
i
++
){
//std::cerr << " vector element is " << hashes_vect.at(i) << std::endl;
result
[
"hashes"
][
i
]
=
hashes_vect
.
at
(
i
);
result
[
"hashes"
][
i
]
=
hashes_vect
.
at
(
i
);
}
}
}
catch
(
RPCException
&
_e
)
{
}
catch
(
RPCException
&
_e
)
{
...
@@ -55,6 +53,9 @@ Json::Value SignByHashImpl(const std::string& hash, int status){
...
@@ -55,6 +53,9 @@ Json::Value SignByHashImpl(const std::string& hash, int status){
std
::
string
csr_db_key
=
"CSR:HASH:"
+
hash
;
std
::
string
csr_db_key
=
"CSR:HASH:"
+
hash
;
std
::
shared_ptr
<
std
::
string
>
csr_ptr
=
csrDb
->
readString
(
csr_db_key
);
std
::
shared_ptr
<
std
::
string
>
csr_ptr
=
csrDb
->
readString
(
csr_db_key
);
if
(
csr_ptr
==
nullptr
){
throw
RPCException
(
KEY_SHARE_DOES_NOT_EXIST
,
"HASH DOES NOT EXIST IN DB"
);
}
if
(
status
==
0
)
{
if
(
status
==
0
)
{
std
::
string
csr_name
=
"cert/"
+
hash
+
".csr"
;
std
::
string
csr_name
=
"cert/"
+
hash
+
".csr"
;
...
@@ -62,6 +63,7 @@ Json::Value SignByHashImpl(const std::string& hash, int status){
...
@@ -62,6 +63,7 @@ Json::Value SignByHashImpl(const std::string& hash, int status){
outfile
<<
*
csr_ptr
<<
std
::
endl
;
outfile
<<
*
csr_ptr
<<
std
::
endl
;
outfile
.
close
();
outfile
.
close
();
if
(
access
(
csr_name
.
c_str
(),
F_OK
)
!=
0
)
{
if
(
access
(
csr_name
.
c_str
(),
F_OK
)
!=
0
)
{
csrDb
->
deleteKey
(
csr_db_key
);
throw
RPCException
(
FILE_NOT_FOUND
,
"Csr does not exist"
);
throw
RPCException
(
FILE_NOT_FOUND
,
"Csr does not exist"
);
}
}
...
...
SGXRegistrationServer.cpp
View file @
903a6e2b
...
@@ -70,6 +70,8 @@ Json::Value SignCertificateImpl(const std::string& csr, bool auto_sign = false){
...
@@ -70,6 +70,8 @@ Json::Value SignCertificateImpl(const std::string& csr, bool auto_sign = false){
}
}
else
{
else
{
std
::
cerr
<<
"CLIENT CERTIFICATE GENERATION FAILED"
<<
std
::
endl
;
std
::
cerr
<<
"CLIENT CERTIFICATE GENERATION FAILED"
<<
std
::
endl
;
std
::
string
status_db_key
=
"CSR:HASH:"
+
hash
+
"STATUS:"
;
csrStatusDb
->
writeDataUnique
(
status_db_key
,
std
::
to_string
(
FAIL_TO_CREATE_CERTIFICATE
));
throw
RPCException
(
FAIL_TO_CREATE_CERTIFICATE
,
"CLIENT CERTIFICATE GENERATION FAILED"
);
throw
RPCException
(
FAIL_TO_CREATE_CERTIFICATE
,
"CLIENT CERTIFICATE GENERATION FAILED"
);
//exit(-1);
//exit(-1);
}
}
...
@@ -93,21 +95,13 @@ Json::Value SignCertificateImpl(const std::string& csr, bool auto_sign = false){
...
@@ -93,21 +95,13 @@ Json::Value SignCertificateImpl(const std::string& csr, bool auto_sign = false){
Json
::
Value
GetSertificateImpl
(
const
std
::
string
&
hash
){
Json
::
Value
GetSertificateImpl
(
const
std
::
string
&
hash
){
Json
::
Value
result
;
Json
::
Value
result
;
result
[
"status"
]
=
1
;
result
[
"errorMessage"
]
=
""
;
std
::
string
cert
;
std
::
string
cert
;
try
{
try
{
// std::string rejected_name = "rejected_" + hash + ".txt";
// if (access(rejected_name.c_str(), F_OK) == 0){
// result["status"] = 2;
// result["cert"] = "";
// return result;
// }
std
::
string
db_key
=
"CSR:HASH:"
+
hash
+
"STATUS:"
;
std
::
string
db_key
=
"CSR:HASH:"
+
hash
+
"STATUS:"
;
std
::
shared_ptr
<
string
>
status_str_ptr
=
csrStatusDb
->
readString
(
db_key
);
std
::
shared_ptr
<
string
>
status_str_ptr
=
csrStatusDb
->
readString
(
db_key
);
if
(
status_str_ptr
==
nullptr
){
if
(
status_str_ptr
==
nullptr
){
throw
RPCException
(
FILE_NOT_FOUND
,
"Data with this name does not exist in csr db"
);
throw
RPCException
(
KEY_SHARE_DOES_NOT_EXIST
,
"Data with this name does not exist in csr db"
);
}
}
int
status
=
std
::
atoi
(
status_str_ptr
->
c_str
());
int
status
=
std
::
atoi
(
status_str_ptr
->
c_str
());
...
@@ -117,6 +111,9 @@ Json::Value GetSertificateImpl(const std::string& hash){
...
@@ -117,6 +111,9 @@ Json::Value GetSertificateImpl(const std::string& hash){
//if (access(crt_name.c_str(), F_OK) == 0){
//if (access(crt_name.c_str(), F_OK) == 0){
std
::
ifstream
infile
(
crt_name
);
std
::
ifstream
infile
(
crt_name
);
if
(
!
infile
.
is_open
())
{
if
(
!
infile
.
is_open
())
{
std
::
string
status_db_key
=
"CSR:HASH:"
+
hash
+
"STATUS:"
;
csrStatusDb
->
deleteKey
(
status_db_key
);
csrStatusDb
->
writeDataUnique
(
status_db_key
,
std
::
to_string
(
FILE_NOT_FOUND
));
throw
RPCException
(
FILE_NOT_FOUND
,
"Certificate does not exist"
);
throw
RPCException
(
FILE_NOT_FOUND
,
"Certificate does not exist"
);
}
else
{
}
else
{
ostringstream
ss
;
ostringstream
ss
;
...
@@ -124,23 +121,19 @@ Json::Value GetSertificateImpl(const std::string& hash){
...
@@ -124,23 +121,19 @@ Json::Value GetSertificateImpl(const std::string& hash){
cert
=
ss
.
str
();
cert
=
ss
.
str
();
infile
.
close
();
infile
.
close
();
std
::
string
remove_crt
=
"cd cert && rm -rf"
+
hash
+
".crt"
;
std
::
string
remove_crt
=
"cd cert && rm -rf"
+
hash
+
".crt
&& rm -rf "
+
hash
+
".csr
"
;
system
(
remove_crt
.
c_str
());
system
(
remove_crt
.
c_str
());
// result["cert"] = cert;
// result["status"] = 0;
}
}
}
}
// else if (access(crt_name.c_str(), F_OK) != 0){
// result["status"] = 1;
result
[
"status"
]
=
status
;
// result["cert"] = "";
result
[
"cert"
]
=
cert
;
// }
}
catch
(
RPCException
&
_e
)
{
}
catch
(
RPCException
&
_e
)
{
std
::
cerr
<<
" err str "
<<
_e
.
errString
<<
std
::
endl
;
std
::
cerr
<<
" err str "
<<
_e
.
errString
<<
std
::
endl
;
result
[
"status"
]
=
_e
.
status
;
result
[
"status"
]
=
_e
.
status
;
result
[
"errorMessage"
]
=
_e
.
errString
;
result
[
"errorMessage"
]
=
_e
.
errString
;
result
[
"status"
]
=
1
;
}
}
return
result
;
return
result
;
...
...
abstractCSRManagerServer.h
0 → 100644
View file @
903a6e2b
//
// Created by kladko on 12/24/19.
//
#ifndef SGXD_ABSTRACTCSRMANAGERSERVER_H
#define SGXD_ABSTRACTCSRMANAGERSERVER_H
#include <jsonrpccpp/server.h>
#include <iostream>
class
abstractCSRManagerServer
:
public
jsonrpc
::
AbstractServer
<
abstractCSRManagerServer
>
{
public
:
abstractCSRManagerServer
(
jsonrpc
::
AbstractServerConnector
&
conn
,
jsonrpc
::
serverVersion_t
type
=
jsonrpc
::
JSONRPC_SERVER_V2
)
:
jsonrpc
::
AbstractServer
<
abstractCSRManagerServer
>
(
conn
,
type
)
{
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"GetUnsignedCSRs"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
NULL
),
&
abstractCSRManagerServer
::
GetUnsignedCSRsI
);
this
->
bindAndAddMethod
(
jsonrpc
::
Procedure
(
"SignByHash"
,
jsonrpc
::
PARAMS_BY_NAME
,
jsonrpc
::
JSON_OBJECT
,
"hash"
,
jsonrpc
::
JSON_STRING
,
"status"
,
jsonrpc
::
JSON_INTEGER
,
NULL
),
&
abstractCSRManagerServer
::
SignByHashI
);
}
inline
virtual
void
GetUnsignedCSRsI
(
const
Json
::
Value
&
request
,
Json
::
Value
&
response
)
{
(
void
)
request
;
response
=
this
->
GetUnsignedCSRs
();
}
inline
virtual
void
SignByHashI
(
const
Json
::
Value
&
request
,
Json
::
Value
&
response
)
{
response
=
this
->
SignByHash
(
request
[
"hash"
].
asString
(),
request
[
"status"
].
asInt
());
}
virtual
Json
::
Value
GetUnsignedCSRs
()
=
0
;
virtual
Json
::
Value
SignByHash
(
const
std
::
string
&
hash
,
int
status
)
=
0
;
};
#endif //SGXD_ABSTRACTCSRMANAGERSERVER_H
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