Open Enclave  0.15.0
enclave.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_ENCLAVE_H
11 #define _OE_ENCLAVE_H
12 
13 #ifdef _OE_HOST_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 "bits/defs.h"
19 #include "bits/evidence.h"
20 #include "bits/exception.h"
21 #include "bits/fs.h"
22 #include "bits/module.h"
23 #include "bits/properties.h"
24 #include "bits/result.h"
25 #include "bits/types.h"
26 
30 OE_EXTERNC_BEGIN
31 
36 #ifndef _WIN32
37 #define sscanf_s sscanf
38 #endif
39 
46 #if defined(_ARM_) || defined(_M_ARM) || defined(__arm__) || \
47  defined(__thumb__) || defined(__aarch64__)
48 #define __thread
49 #endif
50 
73  bool is_first_handler,
74  oe_vectored_exception_handler_t vectored_handler);
75 
87  oe_vectored_exception_handler_t vectored_handler);
88 
105 bool oe_is_within_enclave(const void* ptr, size_t size);
106 
123 bool oe_is_outside_enclave(const void* ptr, size_t size);
124 
138 void* oe_host_malloc(size_t size);
139 
163 void* oe_host_realloc(void* ptr, size_t size);
164 
179 void* oe_host_calloc(size_t nmemb, size_t size);
180 
190 void oe_host_free(void* ptr);
191 
206 char* oe_host_strndup(const char* str, size_t n);
207 
214 void oe_abort(void) OE_NO_RETURN;
215 
241 void __oe_assert_fail(
242  const char* expr,
243  const char* file,
244  int line,
245  const char* func);
256 #ifndef NDEBUG
257 #define oe_assert(EXPR) \
258  do \
259  { \
260  if (!(EXPR)) \
261  __oe_assert_fail(#EXPR, __FILE__, __LINE__, __FUNCTION__); \
262  } while (0)
263 #else
264 #define oe_assert(EXPR)
265 #endif
266 
267 #if (OE_API_VERSION < 2)
268 #error "Only OE_API_VERSION of 2 is supported"
269 #else
270 #define oe_get_report oe_get_report_v2
271 #endif
272 
297  uint32_t flags,
298  const uint8_t* report_data,
299  size_t report_data_size,
300  const void* opt_params,
301  size_t opt_params_size,
302  uint8_t** report_buffer,
303  size_t* report_buffer_size);
304 
310 void oe_free_report(uint8_t* report_buffer);
311 
312 #if (OE_API_VERSION < 2)
313 #error "Only OE_API_VERSION of 2 is supported"
314 #else
315 #define oe_get_target_info oe_get_target_info_v2
316 #endif
317 
339  const uint8_t* report,
340  size_t report_size,
341  void** target_info_buffer,
342  size_t* target_info_size);
343 
350 void oe_free_target_info(void* target_info);
351 
368  const uint8_t* report,
369  size_t report_size,
370  oe_report_t* parsed_report);
371 
390  const uint8_t* report,
391  size_t report_size,
392  oe_report_t* parsed_report);
393 
394 #if (OE_API_VERSION < 2)
395 #error "Only OE_API_VERSION of 2 is supported"
396 #else
397 #define oe_get_seal_key_by_policy oe_get_seal_key_by_policy_v2
398 #endif
399 
424  oe_seal_policy_t seal_policy,
425  uint8_t** key_buffer,
426  size_t* key_buffer_size,
427  uint8_t** key_info,
428  size_t* key_info_size);
429 
430 #if (OE_API_VERSION < 2)
431 #error "Only OE_API_VERSION of 2 is supported"
432 #else
433 #define oe_get_seal_key oe_get_seal_key_v2
434 #endif
435 
457  oe_seal_policy_t seal_policy,
458  const oe_asymmetric_key_params_t* key_params,
459  uint8_t** key_buffer,
460  size_t* key_buffer_size,
461  uint8_t** key_info,
462  size_t* key_info_size);
463 
481  const oe_asymmetric_key_params_t* key_params,
482  const uint8_t* key_info,
483  size_t key_info_size,
484  uint8_t** key_buffer,
485  size_t* key_buffer_size);
486 
508  oe_seal_policy_t seal_policy,
509  const oe_asymmetric_key_params_t* key_params,
510  uint8_t** key_buffer,
511  size_t* key_buffer_size,
512  uint8_t** key_info,
513  size_t* key_info_size);
514 
532  const oe_asymmetric_key_params_t* key_params,
533  const uint8_t* key_info,
534  size_t key_info_size,
535  uint8_t** key_buffer,
536  size_t* key_buffer_size);
537 
547 void oe_free_key(
548  uint8_t* key_buffer,
549  size_t key_buffer_size,
550  uint8_t* key_info,
551  size_t key_info_size);
552 
573  const uint8_t* key_info,
574  size_t key_info_size,
575  uint8_t** key_buffer,
576  size_t* key_buffer_size);
577 
584 void oe_free_seal_key(uint8_t* key_buffer, uint8_t* key_info);
585 
599 
610 oe_result_t oe_random(void* data, size_t size);
611 
635  const unsigned char* subject_name,
636  uint8_t* private_key,
637  size_t private_key_size,
638  uint8_t* public_key,
639  size_t public_key_size,
640  uint8_t** output_cert,
641  size_t* output_cert_size);
642 
647 void oe_free_attestation_certificate(uint8_t* cert);
648 
654 typedef oe_result_t (
656 
681  uint8_t* cert_in_der,
682  size_t cert_in_der_len,
683  oe_identity_verify_callback_t enclave_identity_callback,
684  void* arg);
685 
686 OE_EXTERNC_END
687 
688 #endif /* _OE_ENCLAVE_H */
oe_host_strndup
char * oe_host_strndup(const char *str, size_t n)
Make a heap copy of a string.
_oe_report
Structure to hold the parsed form of a report.
Definition: report.h:112
oe_random
oe_result_t oe_random(void *data, size_t size)
Generate a sequence of random bytes.
oe_is_within_enclave
bool oe_is_within_enclave(const void *ptr, size_t size)
Check whether the given buffer is strictly within the enclave.
types.h
oe_get_public_key_by_policy
oe_result_t oe_get_public_key_by_policy(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_get_public_key
oe_result_t oe_get_public_key(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_is_outside_enclave
bool oe_is_outside_enclave(const void *ptr, size_t size)
Check whether the given buffer is strictly outside 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.
module.h
_oe_identity
Structure to represent the identity of an enclave.
Definition: report.h:80
oe_free_attestation_certificate
void oe_free_attestation_certificate(uint8_t *cert)
Free the given cert.
oe_free_report
void oe_free_report(uint8_t *report_buffer)
Frees a report buffer obtained from oe_get_report.
oe_generate_attestation_certificate
oe_result_t oe_generate_attestation_certificate(const unsigned char *subject_name, uint8_t *private_key, size_t private_key_size, uint8_t *public_key, size_t public_key_size, uint8_t **output_cert, size_t *output_cert_size)
oe_generate_attestation_certificate.
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_host_realloc
void * oe_host_realloc(void *ptr, size_t size)
Reallocate bytes from the host's heap.
oe_host_malloc
void * oe_host_malloc(size_t size)
Allocate bytes from the host's heap.
oe_verify_attestation_certificate
oe_result_t oe_verify_attestation_certificate(uint8_t *cert_in_der, size_t cert_in_der_len, oe_identity_verify_callback_t enclave_identity_callback, void *arg)
oe_verify_attestation_certificate
oe_get_private_key
oe_result_t oe_get_private_key(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 private key that is associated with the identity of the enclave.
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_get_private_key_by_policy
oe_result_t oe_get_private_key_by_policy(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 private key that is associated with the identity of the enclave and the specified policy.
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_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_abort
void oe_abort(void) OE_NO_RETURN
Abort execution of the enclave.
oe_get_seal_key_v2
oe_result_t oe_get_seal_key_v2(const uint8_t *key_info, size_t key_info_size, uint8_t **key_buffer, size_t *key_buffer_size)
Get a symmetric encryption key from the enclave platform using existing key information.
oe_get_enclave
oe_enclave_t * oe_get_enclave(void)
Obtains the enclave handle.
oe_vectored_exception_handler_t
uint64_t(* oe_vectored_exception_handler_t)(oe_exception_record_t *exception_context)
oe_vectored_exception_handler_t - Function pointer for a vectored exception handler in an enclave.
Definition: exception.h:169
oe_verify_report
oe_result_t oe_verify_report(const uint8_t *report, size_t report_size, oe_report_t *parsed_report)
Verify the integrity of the report and its signature.
result.h
oe_identity_verify_callback_t
oe_result_t(* oe_identity_verify_callback_t)(oe_identity_t *identity, void *arg)
identity validation callback type
Definition: enclave.h:655
evidence.h
oe_host_calloc
void * oe_host_calloc(size_t nmemb, size_t size)
Allocate zero-filled bytes from the host's heap.
oe_remove_vectored_exception_handler
oe_result_t oe_remove_vectored_exception_handler(oe_vectored_exception_handler_t vectored_handler)
Remove an existing vectored exception handler.
oe_host_free
void oe_host_free(void *ptr)
Release allocated memory.
oe_free_seal_key
void oe_free_seal_key(uint8_t *key_buffer, uint8_t *key_info)
Frees a key and/or key info.
oe_get_report_v2
oe_result_t oe_get_report_v2(uint32_t flags, const uint8_t *report_data, size_t report_data_size, 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.
oe_free_target_info
void oe_free_target_info(void *target_info)
Frees target info obtained from oe_get_target_info.
exception.h
properties.h
oe_get_seal_key_by_policy_v2
oe_result_t oe_get_seal_key_by_policy_v2(oe_seal_policy_t seal_policy, uint8_t **key_buffer, size_t *key_buffer_size, uint8_t **key_info, size_t *key_info_size)
Get a symmetric encryption key derived from the specified policy and coupled to the enclave platform.
oe_add_vectored_exception_handler
oe_result_t oe_add_vectored_exception_handler(bool is_first_handler, oe_vectored_exception_handler_t vectored_handler)
OP-TEE provides single-threaded enclaves only, and its ELF loader does not support thread-local reloc...
oe_result_t
enum _oe_result oe_result_t
This enumeration type defines return codes for Open Enclave functions.