mirror of
https://github.com/corda/corda.git
synced 2025-06-23 17:53:31 +00:00
Add sgx build, documentation, verify-enclave
This commit is contained in:
39
sgx-jvm/jvm-enclave/standalone/CMakeLists.txt
Normal file
39
sgx-jvm/jvm-enclave/standalone/CMakeLists.txt
Normal file
@ -0,0 +1,39 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
project(standalone_sgx_verify)
|
||||
|
||||
#
|
||||
# Enclave library
|
||||
#
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../enclave ${CMAKE_CURRENT_SOURCE_DIR}/../enclave/build)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -g")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-DNDEBUG -DEDEBUG -UDEBUG -g") # For "pre-release" mode
|
||||
|
||||
#
|
||||
# SGX SDK
|
||||
#
|
||||
include_directories("${SGX_SDK}/include")
|
||||
|
||||
add_library(urtslib SHARED IMPORTED)
|
||||
set_target_properties(urtslib PROPERTIES IMPORTED_LOCATION ${SGX_LIBRARY_PATH}/lib${URTS_LIB}.so)
|
||||
|
||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
|
||||
#
|
||||
# Untrusted loader app
|
||||
#
|
||||
|
||||
include_directories(${GENERATED_RPC_DIR})
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../common)
|
||||
# TODO: Do the "-fPIC -wno-attributes" flags matter?
|
||||
|
||||
set(SOURCE_FILES main.cpp)
|
||||
set_source_files_properties(${GENERATED_RPC_DIR}/java_u.c PROPERTIES GENERATED TRUE)
|
||||
add_executable(standalone_sgx_verify ${SOURCE_FILES} $<TARGET_OBJECTS:common>)
|
||||
target_include_directories(standalone_sgx_verify PUBLIC ${SGX_SDK_INCLUDE})
|
||||
target_link_libraries(standalone_sgx_verify urtslib Threads::Threads)
|
||||
add_dependencies(standalone_sgx_verify enclave)
|
39
sgx-jvm/jvm-enclave/standalone/main.cpp
Normal file
39
sgx-jvm/jvm-enclave/standalone/main.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
#include <sgx_urts.h>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include "sgx_utilities.h"
|
||||
#include "java_u.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
sgx_launch_token_t token = {0};
|
||||
sgx_enclave_id_t enclave_id = {0};
|
||||
int updated = 0;
|
||||
|
||||
CHECK_SGX(sgx_create_enclave("../../enclave/build/cordaenclave.signed.so", SGX_DEBUG_FLAG, &token, &updated, &enclave_id, NULL));
|
||||
|
||||
if (argc < 2) {
|
||||
printf("Usage: <executable> /path/to/req/file\n");
|
||||
exit(1);
|
||||
}
|
||||
std::ifstream file(argv[1]);
|
||||
std::vector<char> reqbytes;
|
||||
if (!file.eof() && !file.fail()) {
|
||||
file.seekg(0, std::ios_base::end);
|
||||
std::streampos fileSize = file.tellg();
|
||||
reqbytes.resize(fileSize);
|
||||
|
||||
file.seekg(0, std::ios_base::beg);
|
||||
file.read(&reqbytes[0], fileSize);
|
||||
}
|
||||
if (reqbytes.size() == 0) {
|
||||
printf("Could not load %s\n", argv[1]);
|
||||
}
|
||||
|
||||
char error[1024];
|
||||
CHECK_SGX(check_transaction(enclave_id, reqbytes.data(), reqbytes.size(), &error[0]));
|
||||
|
||||
sgx_destroy_enclave(enclave_id);
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user