Added rpc server

parent d2fa720c
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
#include "sgxwallet.h" #include "sgxwallet.h"
#include "SGXWalletServer.h"
#include "BLSCrypto.h" #include "BLSCrypto.h"
...@@ -132,7 +134,6 @@ void init_daemon() { ...@@ -132,7 +134,6 @@ void init_daemon() {
leveldb::Status status = leveldb::DB::Open(options, "./keysdb", &db); leveldb::Status status = leveldb::DB::Open(options, "./keysdb", &db);
} }
...@@ -161,6 +162,7 @@ bool sign(char* _encryptedKeyHex, char* _hashHex, size_t _t, size_t _n, size_t _ ...@@ -161,6 +162,7 @@ bool sign(char* _encryptedKeyHex, char* _hashHex, size_t _t, size_t _n, size_t _
void init_all() { void init_all() {
init_server();
init_enclave(); init_enclave();
init_daemon(); init_daemon();
} }
\ No newline at end of file
...@@ -16,6 +16,8 @@ EXTERNC void init_all(); ...@@ -16,6 +16,8 @@ EXTERNC void init_all();
EXTERNC void init_daemon(); EXTERNC void init_daemon();
EXTERNC void init_enclave();
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);
EXTERNC int char2int(char _input); EXTERNC int char2int(char _input);
...@@ -26,8 +28,6 @@ EXTERNC bool hex2carray(const char * _hex, uint64_t *_bin_len, ...@@ -26,8 +28,6 @@ EXTERNC bool hex2carray(const char * _hex, uint64_t *_bin_len,
EXTERNC void init_enclave();
#endif //SGXD_BLSCRYPTO_H #endif //SGXD_BLSCRYPTO_H
...@@ -90,7 +90,7 @@ secure_enclave.signed.so: secure_enclave/secure_enclave.signed.so ...@@ -90,7 +90,7 @@ secure_enclave.signed.so: secure_enclave/secure_enclave.signed.so
sgxwallet_LDADD=-l$(SGX_URTS_LIB) -Lleveldb/build -LlibBLS/build -LlibBLS/build/libff/libff -l:libbls.a -l:libleveldb.a -l:libff.a -lgmp -ldl -l:libsgx_capable.a -l:libsgx_tprotected_fs.a -ljsonrpccpp-stub -lpthread -ljsonrpccpp-common -ljsonrpccpp-server -ljsoncpp -lprocps sgxwallet_LDADD=-l$(SGX_URTS_LIB) -Lleveldb/build -LlibBLS/build -LlibBLS/build/libff/libff -l:libbls.a -l:libleveldb.a -l:libff.a -lgmp -ldl -l:libsgx_capable.a -l:libsgx_tprotected_fs.a -ljsonrpccpp-stub -lpthread -ljsonrpccpp-common -ljsonrpccpp-server -ljsoncpp -lprocps
testw_SOURCES=testw.cpp BLSCrypto.cpp BLSPrivateKeyShareSGX.cpp $(COMMON_SRC) testw_SOURCES=testw.cpp SGXWalletServer.cpp BLSCrypto.cpp BLSPrivateKeyShareSGX.cpp $(COMMON_SRC)
nodist_testw_SOURCES=${nodist_sgxwallet_SOURCES} nodist_testw_SOURCES=${nodist_sgxwallet_SOURCES}
EXTRA_testw_DEPENDENCIES=${EXTRA_sgxwallet_DEPENDENCIES} EXTRA_testw_DEPENDENCIES=${EXTRA_sgxwallet_DEPENDENCIES}
testw_LDADD= ${sgxwallet_LDADD} testw_LDADD= ${sgxwallet_LDADD}
\ No newline at end of file
...@@ -68,14 +68,9 @@ Json::Value SGXWalletServer::buildObject(const string &name, int age) { ...@@ -68,14 +68,9 @@ Json::Value SGXWalletServer::buildObject(const string &name, int age) {
string SGXWalletServer::methodWithoutParameters() { return "Test"; } string SGXWalletServer::methodWithoutParameters() { return "Test"; }
int init_server() { int init_server() {
HttpServer httpserver(8383); HttpServer httpserver(1025);
SGXWalletServer s(httpserver, SGXWalletServer s(httpserver,
JSONRPC_SERVER_V1V2); // hybrid server (json-rpc 1.0 & 2.0) JSONRPC_SERVER_V1V2); // hybrid server (json-rpc 1.0 & 2.0)
s.StartListening(); s.StartListening();
cout << "Hit enter to stop the server" << endl;
getchar();
s.StopListening();
return 0; return 0;
} }
\ No newline at end of file
...@@ -5,4 +5,14 @@ ...@@ -5,4 +5,14 @@
#ifndef SGXD_SGXWALLETSERVER_H #ifndef SGXD_SGXWALLETSERVER_H
#define SGXD_SGXWALLETSERVER_H #define SGXD_SGXWALLETSERVER_H
#ifdef __cplusplus
#define EXTERNC extern "C"
#else
#define EXTERNC
#endif
EXTERNC int init_server();
#endif //SGXD_SGXWALLETSERVER_H #endif //SGXD_SGXWALLETSERVER_H
...@@ -68,70 +68,9 @@ int main(int argc, char *argv[]) { ...@@ -68,70 +68,9 @@ int main(int argc, char *argv[]) {
init_all(); init_all();
while (true) {
const char *key = "4160780231445160889237664391382223604184857153814275770598" sleep(10);
"791864649971919844";
char* keyArray = calloc(128, 1);
uint8_t* encryptedKey = calloc(1024, 1);
char* errMsg = calloc(1024,1);
strncpy((char *)keyArray, (char*)key, 128);
int err_status = 0;
unsigned int enc_len = 0;
status = encrypt_key(eid, &err_status, errMsg, keyArray, encryptedKey, &enc_len);
if (status != SGX_SUCCESS) {
printf("ECALL encrypt_key: 0x%04x\n", status);
return 1;
}
printf("Encrypt key completed with status: %d %s \n", err_status, errMsg);
printf(" Encrypted key len %d\n", enc_len);
char result[2* BUF_LEN];
carray2Hex(encryptedKey, enc_len, result);
uint64_t dec_len = 0;
uint8_t bin[BUF_LEN];
if (!hex2carray(result, &dec_len, bin)) {
printf("hex2carray returned false");
}
for (int i=0; i < dec_len; i++) {
if (bin[i] != encryptedKey[i]) {
printf("Hex does not match");
return 1;
}
} }
if (dec_len != enc_len) {
printf("Dec_len != enc_len %d %d \n", (uint32_t) dec_len, (uint32_t) enc_len);
return 1;
}
gmp_printf("Result: %s", result);
gmp_printf("\n Length: %d \n", enc_len);
return 0; return 0;
} }
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