Create module hash for each module in SGX lib-rats (#1745)

Current SGX lib-rats wasm module hash is stored in a global buffer,
which may be overwritten if there are multiple wasm module loadings.
We move the module hash into the enclave module to resolve the issue.

And rename the SGX_IPFS macro/variable in Makefile and Enclave.edl to
make the code more consistent.

And refine the sgx-ra sample document.
This commit is contained in:
Wenyong Huang
2022-11-24 21:48:50 +08:00
committed by GitHub
parent 1032aac60b
commit 29b76dd275
12 changed files with 131 additions and 26 deletions

View File

@ -11,9 +11,14 @@
#include <stdint.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
#define SGX_QUOTE_MAX_SIZE 8192
#define SGX_USER_DATA_SIZE 64
#define SGX_MEASUREMENT_SIZE 32
/* clang-format off */
typedef struct rats_sgx_evidence {
uint8_t quote[SGX_QUOTE_MAX_SIZE]; /* The quote of the Enclave */
@ -28,4 +33,8 @@ typedef struct rats_sgx_evidence {
} rats_sgx_evidence_t;
/* clang-format on */
#endif
#ifdef __cplusplus
}
#endif
#endif

View File

@ -16,13 +16,13 @@
#include "bh_common.h"
#include "lib_rats_common.h"
extern char wasm_module_hash[SHA256_DIGEST_LENGTH];
static int
librats_collect_wrapper(wasm_exec_env_t exec_env, char **evidence_json,
const char *buffer, uint32_t buffer_size)
{
wasm_module_inst_t module_inst = get_module_inst(exec_env);
wasm_module_t module = wasm_runtime_get_module(module_inst);
char *wasm_module_hash = wasm_runtime_get_module_hash(module);
char *json, *str_ret;
uint32_t str_ret_offset;
@ -112,4 +112,4 @@ get_lib_rats_export_apis(NativeSymbol **p_lib_rats_apis)
{
*p_lib_rats_apis = native_symbols_lib_rats;
return sizeof(native_symbols_lib_rats) / sizeof(NativeSymbol);
}
}

View File

@ -10,6 +10,7 @@
#include <stdint.h>
#include <string.h>
#include "lib_rats_common.h"
#ifdef __cplusplus
@ -44,4 +45,4 @@ librats_parse_evidence(const char *evidence_json, uint32_t json_size,
}
#endif
#endif
#endif