Open Enclave  0.15.0
host.h
Go to the documentation of this file.
1 // Copyright (c) Open Enclave SDK contributors.
2 // Licensed under the MIT License.
3 
10 #ifndef _OE_HOST_H
11 #define _OE_HOST_H
12 
13 #ifdef _OE_ENCLAVE_H
14 #error "enclave.h and host.h must not be included in the same compilation unit."
15 #endif
16 
17 #include <openenclave/bits/asym_keys.h>
18 #include <stdarg.h>
19 #include <stddef.h>
20 #include <stdint.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include "bits/defs.h"
25 #include "bits/eeid.h"
26 #include "bits/evidence.h"
27 #include "bits/result.h"
28 #include "bits/types.h"
29 #include "host_verify.h"
30 
31 OE_EXTERNC_BEGIN
32 
33 #ifndef _WIN32
34 #define _getpid getpid
35 #define sscanf_s sscanf
36 #define sprintf_s(buffer, size, format, argument) \
37  sprintf(buffer, format, argument)
38 #define strcat_s(destination, destination_size, source) \
39  strcat(destination, source)
40 #define strcpy_s(destination, destination_size, source) \
41  ; \
42  { \
43  (void)(destination_size); \
44  strcpy(destination, source); \
45  }
46 #define _strdup strdup
47 #define strncat_s(destination, destination_size, source, source_size) \
48  strncat(destination, source, source_size)
49 #define fopen_s(pfp, name, mode) *(pfp) = fopen((name), (mode))
50 #endif
51 
62 #define OE_ENCLAVE_FLAG_DEBUG 0x00000001u
63 
67 #define OE_ENCLAVE_FLAG_SIMULATE 0x00000002u
68 
77 #define OE_ENCLAVE_FLAG_SGX_KSS 0x00000004u
78 
79 #define OE_ENCLAVE_FLAG_RESERVED \
80  (~(OE_ENCLAVE_FLAG_DEBUG | OE_ENCLAVE_FLAG_SIMULATE))
81 
89 typedef void (*oe_ocall_func_t)(
90  const uint8_t* input_buffer,
91  size_t input_buffer_size,
92  uint8_t* output_buffer,
93  size_t output_buffer_size,
94  size_t* output_bytes_written);
95 
100 {
101  OE_ENCLAVE_SETTING_CONTEXT_SWITCHLESS = 0xdc73a628,
102 #ifdef OE_WITH_EXPERIMENTAL_EEID
103  OE_EXTENDED_ENCLAVE_INITIALIZATION_DATA = 0x976a8f66,
104 #endif
105  OE_SGX_ENCLAVE_CONFIG_DATA = 0x78b5b41d
107 
112 {
125 
130 {
131  uint8_t config_id[64];
132  uint16_t config_svn;
133  bool ignore_if_unsupported;
135 
140 typedef struct _oe_enclave_setting
141 {
150  union {
152  context_switchless_setting;
153 #ifdef OE_WITH_EXPERIMENTAL_EEID
154  oe_eeid_t* eeid;
155 #endif
156  const oe_sgx_enclave_setting_config_data* config_data;
157  /* Add new setting types here. */
158  } u;
160 
164 typedef struct _oe_ecall_info_t
165 {
166  const char* name;
168 
208  const char* path,
209  oe_enclave_type_t type,
210  uint32_t flags,
211  const oe_enclave_setting_t* settings,
212  uint32_t setting_count,
213  const oe_ocall_func_t* ocall_table,
214  uint32_t ocall_count,
215  const oe_ecall_info_t* ecall_name_table,
216  uint32_t ecall_count,
217  oe_enclave_t** enclave);
218 
232 
233 #if (OE_API_VERSION < 2)
234 #error "Only OE_API_VERSION of 2 is supported"
235 #else
236 #define oe_get_report oe_get_report_v2
237 #endif
238 
261  oe_enclave_t* enclave,
262  uint32_t flags,
263  const void* opt_params,
264  size_t opt_params_size,
265  uint8_t** report_buffer,
266  size_t* report_buffer_size);
267 
273 void oe_free_report(uint8_t* report_buffer);
274 
275 #if (OE_API_VERSION < 2)
276 #error "Only OE_API_VERSION of 2 is supported"
277 #else
278 #define oe_get_target_info oe_get_target_info_v2
279 #endif
280 
302  const uint8_t* report,
303  size_t report_size,
304  void** target_info_buffer,
305  size_t* target_info_size);
306 
312 void oe_free_target_info(void* target_info_buffer);
313 
329  const uint8_t* report,
330  size_t report_size,
331  oe_report_t* parsed_report);
332 
353  oe_enclave_t* enclave,
354  const uint8_t* report,
355  size_t report_size,
356  oe_report_t* parsed_report);
357 
380  oe_enclave_t* enclave,
381  oe_seal_policy_t seal_policy,
382  const oe_asymmetric_key_params_t* key_params,
383  uint8_t** key_buffer,
384  size_t* key_buffer_size,
385  uint8_t** key_info,
386  size_t* key_info_size);
387 
406  oe_enclave_t* enclave,
407  const oe_asymmetric_key_params_t* key_params,
408  const uint8_t* key_info,
409  size_t key_info_size,
410  uint8_t** key_buffer,
411  size_t* key_buffer_size);
412 
422 void oe_free_key(
423  uint8_t* key_buffer,
424  size_t key_buffer_size,
425  uint8_t* key_info,
426  size_t key_info_size);
427 
428 OE_EXTERNC_END
429 
430 #endif /* _OE_HOST_H */
oe_enclave_setting_t
struct _oe_enclave_setting oe_enclave_setting_t
The uniform structure type containing a specific type of enclave setting.
_oe_report
Structure to hold the parsed form of a report.
Definition: report.h:112
oe_enclave_type_t
enum _oe_enclave_type oe_enclave_type_t
This enumeration defines values for the type parameter passed to oe_create_enclave().
oe_verify_report
oe_result_t oe_verify_report(oe_enclave_t *enclave, const uint8_t *report, size_t report_size, oe_report_t *parsed_report)
Verify the integrity of the report and its signature.
oe_free_key
void oe_free_key(uint8_t *key_buffer, size_t key_buffer_size, uint8_t *key_info, size_t key_info_size)
Frees the given key and/or key info.
_oe_enclave_setting::u
union _oe_enclave_setting::@0 u
The specific setting for the enclave, such as for configuring context-switchless calls.
types.h
oe_free_report
void oe_free_report(uint8_t *report_buffer)
Frees a report buffer obtained from oe_get_report.
oe_parse_report
oe_result_t oe_parse_report(const uint8_t *report, size_t report_size, oe_report_t *parsed_report)
Parse an enclave report into a standard format for reading.
oe_get_public_key
oe_result_t oe_get_public_key(oe_enclave_t *enclave, const oe_asymmetric_key_params_t *key_params, const uint8_t *key_info, size_t key_info_size, uint8_t **key_buffer, size_t *key_buffer_size)
Returns a public key that is associated with the identity of the enclave.
oe_seal_policy_t
enum _oe_seal_policy oe_seal_policy_t
This enumeration type defines the policy used to derive a seal key.
_oe_enclave_setting_context_switchless
The setting for context-switchless calls.
Definition: host.h:111
_oe_enclave_setting_context_switchless::max_enclave_workers
size_t max_enclave_workers
Context-switchless ecalls are not enabled yet.
Definition: host.h:123
oe_terminate_enclave
oe_result_t oe_terminate_enclave(oe_enclave_t *enclave)
Terminate an enclave and reclaims its resources.
oe_ecall_info_t
struct _oe_ecall_info_t oe_ecall_info_t
Structure describing an ecall.
oe_enclave_t
struct _oe_enclave oe_enclave_t
This is an opaque handle to an enclave returned by oe_create_enclave().
Definition: types.h:144
oe_ocall_func_t
void(* oe_ocall_func_t)(const uint8_t *input_buffer, size_t input_buffer_size, uint8_t *output_buffer, size_t output_buffer_size, size_t *output_bytes_written)
Type of each function in an ocall-table.
Definition: host.h:89
oe_sgx_enclave_setting_config_data
struct _oe_sgx_enclave_setting_config_data oe_sgx_enclave_setting_config_data
The setting for config_id/config_svn on Ice Lake platform.
_oe_enclave_setting_context_switchless::max_host_workers
size_t max_host_workers
The max number of worker threads for context-switchless ocalls.
Definition: host.h:118
oe_enclave_setting_context_switchless_t
struct _oe_enclave_setting_context_switchless oe_enclave_setting_context_switchless_t
The setting for context-switchless calls.
result.h
_oe_ecall_info_t
Structure describing an ecall.
Definition: host.h:164
_oe_enclave_setting::setting_type
oe_enclave_setting_type_t setting_type
The type of the setting in u
Definition: host.h:145
oe_get_report_v2
oe_result_t oe_get_report_v2(oe_enclave_t *enclave, uint32_t flags, const void *opt_params, size_t opt_params_size, uint8_t **report_buffer, size_t *report_buffer_size)
Get a report signed by the enclave platform for use in attestation.
evidence.h
oe_create_enclave
oe_result_t oe_create_enclave(const char *path, oe_enclave_type_t type, uint32_t flags, const oe_enclave_setting_t *settings, uint32_t setting_count, const oe_ocall_func_t *ocall_table, uint32_t ocall_count, const oe_ecall_info_t *ecall_name_table, uint32_t ecall_count, oe_enclave_t **enclave)
Create an enclave from an enclave image file.
_oe_enclave_setting
The uniform structure type containing a specific type of enclave setting.
Definition: host.h:140
oe_get_target_info_v2
oe_result_t oe_get_target_info_v2(const uint8_t *report, size_t report_size, void **target_info_buffer, size_t *target_info_size)
Extracts additional platform specific data from the report and writes it to target_info_buffer.
_oe_sgx_enclave_setting_config_data
The setting for config_id/config_svn on Ice Lake platform.
Definition: host.h:129
oe_get_public_key_by_policy
oe_result_t oe_get_public_key_by_policy(oe_enclave_t *enclave, oe_seal_policy_t seal_policy, const oe_asymmetric_key_params_t *key_params, uint8_t **key_buffer, size_t *key_buffer_size, uint8_t **key_info, size_t *key_info_size)
Returns a public key that is associated with the identity of the enclave and the specified policy.
oe_enclave_setting_type_t
enum _oe_enclave_setting_type oe_enclave_setting_type_t
Types of settings passed into oe_create_enclave
oe_free_target_info
void oe_free_target_info(void *target_info_buffer)
Frees a target info obtained from oe_get_target_info.
oe_result_t
enum _oe_result oe_result_t
This enumeration type defines return codes for Open Enclave functions.
_oe_enclave_setting_type
_oe_enclave_setting_type
Types of settings passed into oe_create_enclave
Definition: host.h:99