Asylo
Public Types | Public Member Functions | Friends | Related Functions | List of all members
asylo::TrustedApplication Class Reference

Abstract base class for trusted applications. More...

#include <trusted_application.h>

Public Types

enum  State {
  State::kUninitialized, State::kInternalInitializing, State::kUserInitializing, State::kRunning,
  State::kFinalizing, State::kFinalized
}
 An enumeration of possible enclave runtime states. More...
 

Public Member Functions

virtual Status Initialize (const EnclaveConfig &config)
 Implements enclave initialization entry-point. More...
 
virtual Status Run (const EnclaveInput &input, EnclaveOutput *output)
 Implements enclave execution entry-point. More...
 
virtual Status Finalize (const EnclaveFinal &final_input)
 Implements enclave finalization behavior. More...
 
virtual ~TrustedApplication ()=default
 Trivial destructor. More...
 
State GetState () LOCKS_EXCLUDED(mutex_)
 Returns the enclave state in a thread-safe manner. More...
 

Friends

int __asylo_user_init (const char *name, const char *config, size_t config_len, char **output, size_t *output_len)
 
int __asylo_user_run (const char *input, size_t input_len, char **output, size_t *output_len)
 
int __asylo_user_fini (const char *input, size_t input_len, char **output, size_t *output_len)
 
int __asylo_threading_donate ()
 
int __asylo_handle_signal (const char *input, size_t input_len)
 

Related Functions

(Note that these are not member functions.)

TrustedApplicationBuildTrustedApplication ()
 User-supplied factory function for making a trusted application instance. More...
 
TrustedApplicationGetApplicationInstance ()
 Returns the trusted application instance. More...
 

Detailed Description

Abstract base class for trusted applications.

To implement an enclave application, client code declares a TrustedApplication and implements the entry points it wishes to handle. For example:

class HelloWorld : public TrustedApplication {
public:
Status Initialize(const EnclaveConfig &config) override {
enc_untrusted_puts("Hello!");
return Status::OkStatus();
}
Status Run(const EnclaveInput &input, EnclaveOutput *output) override {
enc_untrusted_puts("Running!");
return Status::OkStatus();
}
Status Finalize(const EnclaveFinal &fini) override {
enc_untrusted_puts("Goodbye!");
return Status::OkStatus();
}
};

At startup, the runtime will call the user supplied function BuildTrustedApplication and install the returned instance as the handler for enclave entries events. For instance:

TrustedApplication *BuildTrustedApplication() {
return new HelloWorld;
}

Note that types derived from TrustedApplication must be trivially destructible, and any such destructor will never be invoked by the runtime.

Member Enumeration Documentation

◆ State

An enumeration of possible enclave runtime states.

Enumerator
kUninitialized 

Enclave initialization has not started.

kInternalInitializing 

Asylo internals are initializing.

kUserInitializing 

Asylo internals are initialized.

User-defined initialization is in-progress.

kRunning 

All initialization has completed. The enclave is running.

kFinalizing 

The enclave is finalizing.

kFinalized 

The enclave has finalized.

Constructor & Destructor Documentation

◆ ~TrustedApplication()

virtual asylo::TrustedApplication::~TrustedApplication ( )
virtualdefault

Trivial destructor.

Trivial destructor. Note that classes derived from of TrustedApplication must not add a non-trivial destructor, as they will not be called by the enclave runtime.

Member Function Documentation

◆ Finalize()

virtual Status asylo::TrustedApplication::Finalize ( const EnclaveFinal &  final_input)
inlinevirtual

Implements enclave finalization behavior.

Parameters
final_inputMessage passed on enclave finalization.
Returns
OK status or error

◆ GetState()

State asylo::TrustedApplication::GetState ( )

Returns the enclave state in a thread-safe manner.

◆ Initialize()

virtual Status asylo::TrustedApplication::Initialize ( const EnclaveConfig &  config)
inlinevirtual

Implements enclave initialization entry-point.

Parameters
configThe configuration used to initialize the enclave.
Returns
An OK status or an error if the enclave could not be initialized.

◆ Run()

virtual Status asylo::TrustedApplication::Run ( const EnclaveInput &  input,
EnclaveOutput *  output 
)
inlinevirtual

Implements enclave execution entry-point.

Parameters
inputMessage passed to determine behavior for the Run routine.
outputMessage passed back to the untrusted caller.
Returns
OK status or error

Friends And Related Function Documentation

◆ __asylo_handle_signal

int __asylo_handle_signal ( const char *  input,
size_t  input_len 
)
friend

◆ __asylo_threading_donate

int __asylo_threading_donate ( )
friend

◆ __asylo_user_fini

int __asylo_user_fini ( const char *  input,
size_t  input_len,
char **  output,
size_t *  output_len 
)
friend

◆ __asylo_user_init

int __asylo_user_init ( const char *  name,
const char *  config,
size_t  config_len,
char **  output,
size_t *  output_len 
)
friend

◆ __asylo_user_run

int __asylo_user_run ( const char *  input,
size_t  input_len,
char **  output,
size_t *  output_len 
)
friend

◆ BuildTrustedApplication()

TrustedApplication * BuildTrustedApplication ( )
related

User-supplied factory function for making a trusted application instance.

Returns
A new TrustedApplication instance, or nullptr on failure.

◆ GetApplicationInstance()

TrustedApplication * GetApplicationInstance ( )
related

Returns the trusted application instance.

Returns
The enclave application instance or nullptr on failure.

The documentation for this class was generated from the following file: