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

More return code variants for some possible exceptions on Enclave() creation #3116

Merged
merged 17 commits into from
Oct 22, 2021
12 changes: 12 additions & 0 deletions src/common/enclave_interface_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ enum CreateNodeStatus

/** One of the input buffers is not located outside of the enclave memory */
MemoryNotOutsideEnclave = 5,

/** Enclave initialisation failed */
EnclaveInitFailed = 6,

/** Open Enclave Verifier initialisation failed */
OEVerifierInitFailed = 7,

/** Open Enclave Attester initialisation failed */
OEAttesterInitFailed = 8,

/** OpenSSL RDRAND Init Failed */
OpenSSLRDRANDInitFailed = 9
};

constexpr char const* create_node_result_to_str(CreateNodeStatus result)
achamayou marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
24 changes: 24 additions & 0 deletions src/ds/ccf_exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,28 @@ namespace ccf
private:
std::string result;
};

class ccf_oe_attester_init_error : public ccf_logic_error
{
public:
ccf_oe_attester_init_error(const std::string& what_arg) :
ccf_logic_error(what_arg)
{}
};

class ccf_oe_verifier_init_error : public ccf_logic_error
{
public:
ccf_oe_verifier_init_error(const std::string& what_arg) :
ccf_logic_error(what_arg)
{}
};

class ccf_openssl_rdrand_init_error : public ccf_logic_error
{
public:
ccf_openssl_rdrand_init_error(const std::string& what_arg) :
ccf_logic_error(what_arg)
{}
};
};
2 changes: 1 addition & 1 deletion src/enclave/enclave.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ namespace enclave
ENGINE_set_default(rdrand_engine, ENGINE_METHOD_RAND) != 1)
{
ENGINE_free(rdrand_engine);
throw std::runtime_error(
throw ccf::ccf_openssl_rdrand_init_error(
"could not initialize RDRAND engine for OpenSSL");
}

Expand Down
25 changes: 23 additions & 2 deletions src/enclave/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the Apache 2.0 License.
#include "ccf/version.h"
#include "common/enclave_interface_types.h"
#include "ds/ccf_exception.h"
#include "ds/json.h"
#include "ds/logger.h"
#include "enclave.h"
Expand Down Expand Up @@ -143,9 +144,29 @@ extern "C"
#ifdef DEBUG_CONFIG
reserved_memory = new uint8_t[ec->debug_config.memory_reserve_startup];
#endif
enclave::Enclave* enclave;

auto enclave = new enclave::Enclave(
ec, cc.signature_intervals, cc.consensus_config, cc.curve_id);
try
{
enclave = new enclave::Enclave(
ec, cc.signature_intervals, cc.consensus_config, cc.curve_id);
}
catch (const ccf::ccf_oe_attester_init_error&)
{
return CreateNodeStatus::OEAttesterInitFailed;
}
catch (const ccf::ccf_oe_verifier_init_error&)
{
return CreateNodeStatus::OEVerifierInitFailed;
}
catch (const ccf::ccf_openssl_rdrand_init_error&)
{
return CreateNodeStatus::OpenSSLRDRANDInitFailed;
}
catch (const std::exception&)
{
return CreateNodeStatus::EnclaveInitFailed;
}

if (!enclave->create_new_node(
achamayou marked this conversation as resolved.
Show resolved Hide resolved
start_type,
Expand Down
5 changes: 3 additions & 2 deletions src/enclave/oe_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#else
# include <openenclave/host_verify.h>
#endif
#include "ds/ccf_exception.h"

namespace ccf
{
Expand All @@ -17,7 +18,7 @@ namespace ccf
auto rc = oe_attester_initialize();
if (rc != OE_OK)
{
throw std::logic_error(fmt::format(
throw std::ccf_oe_attester_init_error(fmt::format(
"Failed to initialise evidence attester: {}", oe_result_str(rc)));
}
}
Expand All @@ -26,7 +27,7 @@ namespace ccf
auto rc = oe_verifier_initialize();
if (rc != OE_OK)
{
throw std::logic_error(fmt::format(
throw ccf::ccf_oe_verifier_init_error(fmt::format(
"Failed to initialise evidence verifier: {}", oe_result_str(rc)));
}
}
Expand Down