Fixed server

parent 25f20f28
...@@ -13,12 +13,60 @@ ...@@ -13,12 +13,60 @@
#include <jsonrpccpp/server/connectors/httpserver.h> #include <jsonrpccpp/server/connectors/httpserver.h>
#include "BLSPrivateKeyShareSGX.h" #include "BLSPrivateKeyShareSGX.h"
#include "sgxwallet_common.h"
#include "sgxwallet_common.h"
#include "create_enclave.h"
#include "secure_enclave_u.h"
#include "sgx_detect.h"
#include <gmp.h>
#include <sgx_urts.h>
#include "sgxwallet.h"
#include "BLSCrypto.h" #include "BLSCrypto.h"
void init_enclave() {
eid = 0;
updated = 0;
unsigned long support;
#ifndef SGX_HW_SIM
support = get_sgx_support();
if (!SGX_OK(support)) {
sgx_support_perror(support);
exit(1);
}
#endif
status = sgx_create_enclave_search(ENCLAVE_NAME, SGX_DEBUG_FLAG, &token,
&updated, &eid, 0);
if (status != SGX_SUCCESS) {
if (status == SGX_ERROR_ENCLAVE_FILE_ACCESS) {
fprintf(stderr, "sgx_create_enclave: %s: file not found\n", ENCLAVE_NAME);
fprintf(stderr, "Did you forget to set LD_LIBRARY_PATH?\n");
} else {
fprintf(stderr, "%s: 0x%04x\n", ENCLAVE_NAME, status);
}
exit(1);
}
fprintf(stderr, "Enclave launched\n");
status = tgmp_init(eid);
if (status != SGX_SUCCESS) {
fprintf(stderr, "ECALL tgmp_init: 0x%04x\n", status);
exit(1);
}
fprintf(stderr, "libtgmp initialized\n");
}
int char2int(char _input) { int char2int(char _input) {
if (_input >= '0' && _input <= '9') if (_input >= '0' && _input <= '9')
return _input - '0'; return _input - '0';
...@@ -112,3 +160,7 @@ bool sign(char* _encryptedKeyHex, char* _hashHex, size_t _t, size_t _n, size_t _ ...@@ -112,3 +160,7 @@ bool sign(char* _encryptedKeyHex, char* _hashHex, size_t _t, size_t _n, size_t _
} }
void init_all() {
init_enclave();
init_daemon();
}
\ No newline at end of file
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
#define EXTERNC #define EXTERNC
#endif #endif
EXTERNC void init_all();
EXTERNC void init_daemon(); EXTERNC void init_daemon();
EXTERNC bool sign(char* encryptedKeyHex, char* hashHex, size_t t, size_t n, char* _sig); EXTERNC bool sign(char* encryptedKeyHex, char* hashHex, size_t t, size_t n, char* _sig);
...@@ -24,5 +26,8 @@ EXTERNC bool hex2carray(const char * _hex, uint64_t *_bin_len, ...@@ -24,5 +26,8 @@ EXTERNC bool hex2carray(const char * _hex, uint64_t *_bin_len,
EXTERNC void init_enclave();
#endif //SGXD_BLSCRYPTO_H #endif //SGXD_BLSCRYPTO_H
...@@ -31,18 +31,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ...@@ -31,18 +31,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "sgxwallet_common.h"
#include "create_enclave.h"
#include "secure_enclave_u.h"
#include "sgx_detect.h"
#include <gmp.h>
#include <sgx_urts.h>
#include "sgxwallet.h"
#include "BLSCrypto.h" #include "BLSCrypto.h"
#define ENCLAVE_NAME "secure_enclave.signed.so"
void usage() { void usage() {
...@@ -51,49 +43,11 @@ void usage() { ...@@ -51,49 +43,11 @@ void usage() {
} }
sgx_launch_token_t token = {0}; sgx_launch_token_t token = {0};
sgx_enclave_id_t eid; sgx_enclave_id_t eid;
sgx_status_t status; sgx_status_t status;
int updated; int updated;
void init_enclave() {
eid = 0;
updated = 0;
unsigned long support;
#ifndef SGX_HW_SIM
support = get_sgx_support();
if (!SGX_OK(support)) {
sgx_support_perror(support);
exit(1);
}
#endif
status = sgx_create_enclave_search(ENCLAVE_NAME, SGX_DEBUG_FLAG, &token,
&updated, &eid, 0);
if (status != SGX_SUCCESS) {
if (status == SGX_ERROR_ENCLAVE_FILE_ACCESS) {
fprintf(stderr, "sgx_create_enclave: %s: file not found\n", ENCLAVE_NAME);
fprintf(stderr, "Did you forget to set LD_LIBRARY_PATH?\n");
} else {
fprintf(stderr, "%s: 0x%04x\n", ENCLAVE_NAME, status);
}
exit(1);
}
fprintf(stderr, "Enclave launched\n");
status = tgmp_init(eid);
if (status != SGX_SUCCESS) {
fprintf(stderr, "ECALL tgmp_init: 0x%04x\n", status);
exit(1);
}
fprintf(stderr, "libtgmp initialized\n");
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
int opt; int opt;
...@@ -112,10 +66,7 @@ int main(int argc, char *argv[]) { ...@@ -112,10 +66,7 @@ int main(int argc, char *argv[]) {
if (argc != 0) if (argc != 0)
usage(); usage();
init_daemon(); init_all();
init_enclave();
const char *key = "4160780231445160889237664391382223604184857153814275770598" const char *key = "4160780231445160889237664391382223604184857153814275770598"
......
...@@ -5,7 +5,21 @@ ...@@ -5,7 +5,21 @@
#ifndef SGXD_SGXD_H #ifndef SGXD_SGXD_H
#define SGXD_SGXD_H #define SGXD_SGXD_H
#include "sgxwallet_common.h"
#include "create_enclave.h"
#include "secure_enclave_u.h"
#include "sgx_detect.h"
#include <gmp.h>
#include <sgx_urts.h>
extern sgx_enclave_id_t eid; extern sgx_enclave_id_t eid;
extern int updated;
extern sgx_launch_token_t token;
extern sgx_status_t status;
#define ENCLAVE_NAME "secure_enclave.signed.so"
#endif //SGXD_SGXD_H #endif //SGXD_SGXD_H
...@@ -58,49 +58,6 @@ sgx_status_t status; ...@@ -58,49 +58,6 @@ sgx_status_t status;
int updated; int updated;
void init_enclave() {
eid = 0;
updated = 0;
unsigned long support;
#ifndef SGX_HW_SIM
support = get_sgx_support();
if (!SGX_OK(support)) {
sgx_support_perror(support);
exit(1);
}
#endif
status = sgx_create_enclave_search(ENCLAVE_NAME, SGX_DEBUG_FLAG, &token,
&updated, &eid, 0);
if (status != SGX_SUCCESS) {
if (status == SGX_ERROR_ENCLAVE_FILE_ACCESS) {
fprintf(stderr, "sgx_create_enclave: %s: file not found\n", ENCLAVE_NAME);
fprintf(stderr, "Did you forget to set LD_LIBRARY_PATH?\n");
} else {
fprintf(stderr, "%s: 0x%04x\n", ENCLAVE_NAME, status);
}
exit(1);
}
fprintf(stderr, "Enclave launched\n");
status = tgmp_init(eid);
if (status != SGX_SUCCESS) {
fprintf(stderr, "ECALL tgmp_init: 0x%04x\n", status);
exit(1);
}
fprintf(stderr, "libtgmp initialized\n");
}
void init_all() {
init_enclave();
init_daemon();
}
TEST_CASE( "BLS sign test", "[bls-sign]" ) { TEST_CASE( "BLS sign test", "[bls-sign]" ) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment