Open Enclave  0.9.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/report.h"
26 #include "bits/result.h"
27 #include "bits/types.h"
28 #include "host_verify.h"
29 
30 OE_EXTERNC_BEGIN
31 
32 #ifndef _WIN32
33 #define _getpid getpid
34 #define sscanf_s sscanf
35 #define sprintf_s(buffer, size, format, argument) \
36  sprintf(buffer, format, argument)
37 #define strcat_s(destination, destination_size, source) \
38  strcat(destination, source)
39 #define strcpy_s(destination, destination_size, source) \
40  ; \
41  { \
42  (void)(destination_size); \
43  strcpy(destination, source); \
44  }
45 #define _strdup strdup
46 #define strncat_s(destination, destination_size, source, source_size) \
47  strncat(destination, source, source_size)
48 #endif
49 
60 #define OE_ENCLAVE_FLAG_DEBUG 0x00000001u
61 
65 #define OE_ENCLAVE_FLAG_SIMULATE 0x00000002u
66 
70 #define OE_ENCLAVE_FLAG_RESERVED \
71  (~(OE_ENCLAVE_FLAG_DEBUG | OE_ENCLAVE_FLAG_SIMULATE))
72 
80 typedef void (*oe_ocall_func_t)(
81  const uint8_t* input_buffer,
82  size_t input_buffer_size,
83  uint8_t* output_buffer,
84  size_t output_buffer_size,
85  size_t* output_bytes_written);
86 
91 {
92  OE_ENCLAVE_SETTING_CONTEXT_SWITCHLESS = 0xdc73a628,
94 
99 {
112 
117 typedef struct _oe_enclave_setting
118 {
127  union {
129  context_switchless_setting;
130  /* Add new setting types here. */
131  } u;
133 
169  const char* path,
170  oe_enclave_type_t type,
171  uint32_t flags,
172  const oe_enclave_setting_t* settings,
173  uint32_t setting_count,
174  const oe_ocall_func_t* ocall_table,
175  uint32_t ocall_count,
176  oe_enclave_t** enclave);
177 
191 
192 #if (OE_API_VERSION < 2)
193 #error "Only OE_API_VERSION of 2 is supported"
194 #else
195 #define oe_get_report oe_get_report_v2
196 #endif
197 
220  oe_enclave_t* enclave,
221  uint32_t flags,
222  const void* opt_params,
223  size_t opt_params_size,
224  uint8_t** report_buffer,
225  size_t* report_buffer_size);
226 
232 void oe_free_report(uint8_t* report_buffer);
233 
234 #if (OE_API_VERSION < 2)
235 #error "Only OE_API_VERSION of 2 is supported"
236 #else
237 #define oe_get_target_info oe_get_target_info_v2
238 #endif
239 
261  const uint8_t* report,
262  size_t report_size,
263  void** target_info_buffer,
264  size_t* target_info_size);
265 
271 void oe_free_target_info(void* target_info_buffer);
272 
288  const uint8_t* report,
289  size_t report_size,
290  oe_report_t* parsed_report);
291 
312  oe_enclave_t* enclave,
313  const uint8_t* report,
314  size_t report_size,
315  oe_report_t* parsed_report);
316 
339  oe_enclave_t* enclave,
340  oe_seal_policy_t seal_policy,
341  const oe_asymmetric_key_params_t* key_params,
342  uint8_t** key_buffer,
343  size_t* key_buffer_size,
344  uint8_t** key_info,
345  size_t* key_info_size);
346 
365  oe_enclave_t* enclave,
366  const oe_asymmetric_key_params_t* key_params,
367  const uint8_t* key_info,
368  size_t key_info_size,
369  uint8_t** key_buffer,
370  size_t* key_buffer_size);
371 
381 void oe_free_key(
382  uint8_t* key_buffer,
383  size_t key_buffer_size,
384  uint8_t* key_info,
385  size_t key_info_size);
386 
387 OE_EXTERNC_END
388 
389 #endif /* _OE_HOST_H */
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...
enum _oe_seal_policy oe_seal_policy_t
This enumeration type defines the policy used to derive a seal key.
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, oe_enclave_t **enclave)
Create an enclave from an enclave image file.
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.
This file defines the types used by the OE SDK.
Structure to hold the parsed form of a report.
Definition: report.h:112
enum _oe_enclave_type oe_enclave_type_t
This enumeration defines values for the type parameter passed to oe_create_enclave().
size_t max_host_workers
The max number of worker threads for context-switchless ocalls.
Definition: host.h:105
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.
The setting for context-switchless calls.
Definition: host.h:98
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.
enum _oe_enclave_setting_type oe_enclave_setting_type_t
Types of settings passed into oe_create_enclave
_oe_enclave_setting_type
Types of settings passed into oe_create_enclave
Definition: host.h:90
This file defines Open Enclave return codes (results).
enum _oe_result oe_result_t
This enumeration type defines return codes for Open Enclave functions.
size_t max_enclave_workers
Context-switchless ecalls are not enabled yet.
Definition: host.h:110
struct _oe_enclave_setting_context_switchless oe_enclave_setting_context_switchless_t
The setting for context-switchless calls.
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_type_t setting_type
The type of the setting in u
Definition: host.h:122
void oe_free_report(uint8_t *report_buffer)
Frees a report buffer obtained from oe_get_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_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.
void oe_free_target_info(void *target_info_buffer)
Frees a target info obtained from oe_get_target_info.
oe_result_t oe_terminate_enclave(oe_enclave_t *enclave)
Terminate an enclave and reclaims its resources.
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:80
struct _oe_enclave oe_enclave_t
This is an opaque handle to an enclave returned by oe_create_enclave().
Definition: types.h:144
struct _oe_enclave_setting oe_enclave_setting_t
The uniform structure type containing a specific type of enclave setting.
This file defines structures and options passed to oe_get_report functions.
The uniform structure type containing a specific type of enclave setting.
Definition: host.h:117