Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup SGX stuff in cchost config #6865

Merged
merged 3 commits into from
Feb 28, 2025
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
8 changes: 4 additions & 4 deletions doc/host_config_schema/cchost_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
},
"platform": {
"type": "string",
"enum": ["SGX", "SNP", "Virtual"],
"default": "SGX",
"enum": ["SNP", "Virtual"],
"default": "SNP",
"description": "Trusted Execution Environment platform"
},
"type": {
"type": "string",
"enum": ["Release", "Debug", "Virtual"],
"default": "Release",
"description": "Type of enclave application (only if platform is SGX). \"Virtual\" is deprecated (use ``platform`` instead)"
"description": "Type of enclave application (only if platform is SGX, now deprecated). \"Virtual\" is deprecated (use ``platform`` instead)"
}
},
"description": "This section includes configuration for the enclave application launched by this node",
Expand Down Expand Up @@ -522,7 +522,7 @@
"description": "List of servers used to retrieve attestation report endorsement certificates (SEV-SNP only). The first server in the list is always used and other servers are only specified as fallback. If set, attestation endorsements from ``--snp-security-context-dir-var`` are ignored, but uvm endorsements from that directory are still used."
}
},
"description": "This section includes configuration for the attestation for AMD SEV-SNP platform (ignored for SGX)",
"description": "This section includes configuration for the attestation for AMD SEV-SNP platform.",
"additionalProperties": false
},
"service_data_json_file": {
Expand Down
2 changes: 1 addition & 1 deletion samples/config/join_config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"enclave": {
"file": "libjs_generic.enclave.so.signed",
"platform": "SGX",
"platform": "SNP",
"type": "Release"
},
"network": {
Expand Down
2 changes: 1 addition & 1 deletion samples/config/minimal_config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"enclave": {
"file": "libjs_generic.enclave.so.signed",
"platform": "SGX",
"platform": "SNP",
"type": "Release"
},
"network": {
Expand Down
2 changes: 1 addition & 1 deletion samples/config/minimal_config_redirects_role.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"enclave": {
"file": "libjs_generic.enclave.so.signed",
"platform": "SGX",
"platform": "SNP",
"type": "Release"
},
"network": {
Expand Down
2 changes: 1 addition & 1 deletion samples/config/minimal_config_redirects_static.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"enclave": {
"file": "libjs_generic.enclave.so.signed",
"platform": "SGX",
"platform": "SNP",
"type": "Release"
},
"network": {
Expand Down
2 changes: 1 addition & 1 deletion samples/config/recover_config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"enclave": {
"file": "libjs_generic.enclave.so.signed",
"platform": "SGX",
"platform": "SNP",
"type": "Release"
},
"network": {
Expand Down
2 changes: 1 addition & 1 deletion samples/config/start_config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"enclave": {
"file": "libjs_generic.enclave.so.signed",
"platform": "SGX",
"platform": "SNP",
"type": "Release"
},
"network": {
Expand Down
4 changes: 1 addition & 3 deletions src/host/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ namespace host
};
DECLARE_JSON_ENUM(
EnclavePlatform,
{{EnclavePlatform::SGX, "SGX"},
{EnclavePlatform::SNP, "SNP"},
{EnclavePlatform::VIRTUAL, "Virtual"}});
{{EnclavePlatform::SNP, "SNP"}, {EnclavePlatform::VIRTUAL, "Virtual"}});

enum class LogFormat
{
Expand Down
87 changes: 0 additions & 87 deletions src/host/enclave.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,12 @@
#include <dlfcn.h>
#include <filesystem>

#ifdef PLATFORM_SGX
# include <ccf_u.h>
# include <openenclave/bits/result.h>
# include <openenclave/host.h>
# include <openenclave/trace.h>
#endif

#if defined(PLATFORM_VIRTUAL) || defined(PLATFORM_SNP)
// Include order matters. virtual_enclave.h uses the OE definitions if
// available, else creates its own stubs
# include "enclave/virtual_enclave.h"
#endif

extern "C"
{
#ifdef PLATFORM_SGX
void nop_oe_logger(
void* context,
bool is_enclave,
const struct tm* t,
long int usecs,
oe_log_level_t level,
uint64_t host_thread_id,
const char* message)
{}
#endif
}

namespace host
{
void expect_enclave_file_suffix(
Expand Down Expand Up @@ -88,9 +66,6 @@ namespace host
class Enclave
{
private:
#ifdef PLATFORM_SGX
oe_enclave_t* sgx_handle = nullptr;
#endif
#if defined(PLATFORM_VIRTUAL) || defined(PLATFORM_SNP)
void* virtual_handle = nullptr;
#endif
Expand All @@ -100,7 +75,6 @@ namespace host
* Create an uninitialized enclave hosting the given library.
*
* @param path Path to signed enclave library file
* @param type Type of enclave to load
* @param platform Trusted Execution Platform of enclave, influencing what
* flags should be passed to OE, or whether to dlload a virtual enclave
*/
Expand All @@ -114,42 +88,6 @@ namespace host

switch (platform)
{
case host::EnclavePlatform::SGX:
{
#ifdef PLATFORM_SGX
uint32_t oe_flags = 0;
if (type == host::EnclaveType::DEBUG)
{
expect_enclave_file_suffix(path, ".enclave.so.debuggable", type);
oe_flags |= OE_ENCLAVE_FLAG_DEBUG;
}
else
{
expect_enclave_file_suffix(path, ".enclave.so.signed", type);
}

auto err = oe_create_ccf_enclave(
path.c_str(),
OE_ENCLAVE_TYPE_SGX,
oe_flags,
nullptr,
0,
&sgx_handle);

if (err != OE_OK)
{
throw std::logic_error(
fmt::format("Could not create enclave: {}", oe_result_str(err)));
}
#else
throw std::logic_error(fmt::format(
"SGX enclaves are not supported in current build - cannot launch "
"{}",
path));
#endif // defined(PLATFORM_SGX)
break;
}

case host::EnclavePlatform::SNP:
{
#if defined(PLATFORM_SNP)
Expand Down Expand Up @@ -188,19 +126,6 @@ namespace host

~Enclave()
{
#ifdef PLATFORM_SGX
if (sgx_handle != nullptr)
{
auto err = oe_terminate_enclave(sgx_handle);

if (err != OE_OK)
{
LOG_FAIL_FMT(
"Error while terminating enclave: {}", oe_result_str(err));
}
}
#endif

#if defined(PLATFORM_SNP) || defined(PLATFORM_VIRTUAL)
if (virtual_handle != nullptr)
{
Expand Down Expand Up @@ -251,12 +176,6 @@ namespace host
err = virtual_create_node(virtual_handle, CREATE_NODE_ARGS);
}
#endif
#ifdef PLATFORM_SGX
if (sgx_handle != nullptr)
{
err = enclave_create_node(sgx_handle, CREATE_NODE_ARGS);
}
#endif

if (err != OE_OK || status != CreateNodeStatus::OK)
{
Expand Down Expand Up @@ -298,12 +217,6 @@ namespace host
err = virtual_run(virtual_handle, &ret);
}
#endif
#ifdef PLATFORM_SGX
if (sgx_handle != nullptr)
{
err = enclave_run(sgx_handle, &ret);
}
#endif

if (err != OE_OK)
{
Expand Down