Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
476 changes: 434 additions & 42 deletions 3rdparty/openenclave/ert.patch

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ add_subdirectory(meshentry_premainmock)
add_subdirectory(misc_syscalls)
add_subdirectory(payload_data)
add_subdirectory(payload_image)
add_subdirectory(payload_image_and_linked)
add_subdirectory(payload_linked_only)
add_subdirectory(payload_tls)
add_subdirectory(pthread_create)
add_subdirectory(restart)
Expand Down
41 changes: 41 additions & 0 deletions src/tests/payload_image_and_linked/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
add_custom_command(
OUTPUT test_t.c
DEPENDS ../test.edl
COMMAND openenclave::oeedger8r --trusted
${CMAKE_CURRENT_SOURCE_DIR}/../test.edl ${DEFINE_OE_SGX})

add_executable(erttest_payload_image_and_linked enc.cpp test_t.c)
target_include_directories(erttest_payload_image_and_linked
PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(erttest_payload_image_and_linked oeenclave ertlibc
oe_includes erttest_payload_image_and_linked_linked)

add_library(erttest_payload_image_and_linked_linked SHARED linked.c)
set_property(TARGET erttest_payload_image_and_linked_linked
PROPERTY POSITION_INDEPENDENT_CODE ON)
target_link_libraries(erttest_payload_image_and_linked_linked -pie oe_includes)

add_executable(erttest_payload_image_and_linked_payload payload.c)
set_property(TARGET erttest_payload_image_and_linked_payload
PROPERTY POSITION_INDEPENDENT_CODE ON)
target_link_libraries(erttest_payload_image_and_linked_payload -pie oe_includes)

add_custom_command(OUTPUT private.pem COMMAND openssl genrsa -out private.pem
-3 3072)
add_custom_command(
OUTPUT signed
DEPENDS erttest_payload_image_and_linked
erttest_payload_image_and_linked_linked
erttest_payload_image_and_linked_payload private.pem enclave.conf
COMMAND
openenclave::oesign sign -e $<TARGET_FILE:erttest_payload_image_and_linked>
-c ${CMAKE_CURRENT_SOURCE_DIR}/enclave.conf -k private.pem --payload
$<TARGET_FILE:erttest_payload_image_and_linked_payload>
COMMAND touch signed)
add_custom_target(erttest_payload_image_and_linked_sign ALL DEPENDS signed)

add_test(
NAME tests/ert/payload_image_and_linked
COMMAND
erttest_host
erttest_payload_image_and_linked:erttest_payload_image_and_linked_payload)
30 changes: 30 additions & 0 deletions src/tests/payload_image_and_linked/enc.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <elf.h>
#include <openenclave/ert.h>
#include <openenclave/internal/tests.h>
#include <cstdlib>
#include "test_t.h"

extern "C" int linked_test();

using namespace ert;

OE_EXPORT extern "C" void __libc_start_main(int payload_main(...))
{
OE_TEST(payload_main() == 2);
exit(0);
}

void test_ecall()
{
OE_TEST(linked_test() == 2);

// get payload entry point
const auto base = static_cast<const uint8_t*>(payload::get_base());
OE_TEST(base);
const auto& ehdr = *reinterpret_cast<const Elf64_Ehdr*>(base);
OE_TEST(ehdr.e_entry);
const auto entry = (void (*)())(base + ehdr.e_entry);

entry();
OE_TEST(false); // unreachable
}
6 changes: 6 additions & 0 deletions src/tests/payload_image_and_linked/enclave.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Debug=1
NumHeapPages=64
NumStackPages=64
NumTCS=1
ProductID=1
SecurityVersion=1
11 changes: 11 additions & 0 deletions src/tests/payload_image_and_linked/linked.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
static int x = 1;

__attribute__((constructor)) void init_enclave()
{
++x;
}

int linked_test()
{
return x;
}
16 changes: 16 additions & 0 deletions src/tests/payload_image_and_linked/payload.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <openenclave/bits/properties.h>

static int x = 1;

int main()
{
return x;
}

__attribute__((constructor)) void init_enclave()
{
++x;
}

__attribute__((section(OE_INFO_SECTION_NAME))) volatile const char
oe_enclave_properties_sgx[0x1000];
30 changes: 30 additions & 0 deletions src/tests/payload_linked_only/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
add_custom_command(
OUTPUT test_t.c
DEPENDS ../test.edl
COMMAND openenclave::oeedger8r --trusted
${CMAKE_CURRENT_SOURCE_DIR}/../test.edl ${DEFINE_OE_SGX})

add_executable(erttest_payload_linked_only enc.cpp test_t.c)
target_include_directories(erttest_payload_linked_only
PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(erttest_payload_linked_only oeenclave ertlibc oe_includes
erttest_payload_linked_only_linked)

add_library(erttest_payload_linked_only_linked SHARED linked.c)
set_property(TARGET erttest_payload_linked_only_linked
PROPERTY POSITION_INDEPENDENT_CODE ON)
target_link_libraries(erttest_payload_linked_only_linked -pie oe_includes)

add_custom_command(OUTPUT private.pem COMMAND openssl genrsa -out private.pem
-3 3072)
add_custom_command(
OUTPUT signed
DEPENDS erttest_payload_linked_only erttest_payload_linked_only_linked
private.pem enclave.conf
COMMAND openenclave::oesign sign -e $<TARGET_FILE:erttest_payload_linked_only>
-c ${CMAKE_CURRENT_SOURCE_DIR}/enclave.conf -k private.pem
COMMAND touch signed)
add_custom_target(erttest_payload_linked_only_sign ALL DEPENDS signed)

add_test(NAME tests/ert/payload_linked_only
COMMAND erttest_host erttest_payload_linked_only.signed)
9 changes: 9 additions & 0 deletions src/tests/payload_linked_only/enc.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <openenclave/internal/tests.h>
#include "test_t.h"

extern "C" int linked_test();

void test_ecall()
{
OE_TEST(linked_test() == 2);
}
6 changes: 6 additions & 0 deletions src/tests/payload_linked_only/enclave.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Debug=1
NumHeapPages=64
NumStackPages=64
NumTCS=1
ProductID=1
SecurityVersion=1
4 changes: 4 additions & 0 deletions src/tests/payload_linked_only/linked.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
int linked_test()
{
return 2;
}