英特尔 SGX 的本地认证
Local attestation with Intel SGX
我正在尝试在从两个不同应用程序创建的两个 enclave 之间执行本地证明。
为 Linux here 提供的示例代码创建了 3 个不同的飞地,然后在它们之间建立安全连接。但是这些飞地都是由同一个应用程序创建的,因此知道所有飞地 ID。
如果两个不同的应用程序正在创建自己的应该相互通信的 enclave,那么源 enclave 将如何知道目标 enclave 的 ID?该 ID 是否必须以 "general" 方式 (IPC) 从一个应用程序传输到 enclave?
我尝试了一些简单的测试,方法是启动目标飞地并打印其 ID:“26ce00000002”
然后我在本地证明示例中使用此 ID 尝试连接到此 运行 目标飞地:
uint64_t wrapper(const char *c) {
errno = 0;
uint64_t result = strtoull(c, NULL, 16);
if (errno == EINVAL) {
cout << "WRONG NUMBER" << endl;
} else if (errno == ERANGE) {
cout << "Too big\n";
}
return result;
}
uint32_t load_enclaves() {
uint32_t enclave_temp_no;
int ret, launch_token_updated;
sgx_launch_token_t launch_token;
enclave_temp_no = 0;
ret = sgx_create_enclave(ENCLAVE1_PATH, SGX_DEBUG_FLAG, &launch_token, &launch_token_updated, &e1_enclave_id, NULL);
if (ret != SGX_SUCCESS) {
return ret;
}
enclave_temp_no++;
g_enclave_id_map.insert(std::pair<sgx_enclave_id_t, uint32_t>(e1_enclave_id, enclave_temp_no));
const char *test = "26ce00000002";
e2_enclave_id = wrapper(test);
enclave_temp_no++;
g_enclave_id_map.insert(std::pair<sgx_enclave_id_t, uint32_t>(e2_enclave_id, enclave_temp_no));
return SGX_SUCCESS;
}
int main(int argc, char **argv) {
uint32_t ret_status;
sgx_status_t status;
if(load_enclaves() != SGX_SUCCESS) {
printf("\nLoad Enclave Failure");
}
printf("\nAvaliable Enclaves");
printf("\nEnclave1 - EnclaveID %lx",e1_enclave_id);
printf("\nEnclave2 - EnclaveID %lx",e2_enclave_id);
do {
//Test Create session between Enclave1(Source) and Enclave2(Destination)
status = Enclave1_test_create_session(e1_enclave_id, &ret_status, e1_enclave_id, e2_enclave_id);
if (status!=SGX_SUCCESS)
{
printf("Enclave1_test_create_session Ecall failed: Error status code is %x", status);
print_error_message(status);
break;
}
else
{
if(ret_status==0)
{
printf("\n\nSecure Channel Establishment between Source (E1) and Destination (E2) Enclaves successful !!!");
}
else
{
printf("\nSession establishment and key exchange failure between Source (E1) and Destination (E2): Error return status is %x\n", ret_status);
break;
}
}
当使用源 enclave 执行本地证明程序时,我收到 "SGX_ERROR_INVALID_ENCLAVE_ID" 错误?这个错误不是由本地证明示例程序引发的,而是来自 SGX 库中的某个地方,我不知道为什么因为目标飞地仍然是 运行,因此 ID 应该存在!?
我们不需要安全连接来交换飞地 ID。应用程序可以将飞地 ID 与飞地名称一起存储在注册表或磁盘上,飞地名称可以由相应的应用程序检索以获得所需飞地的 ID。然后,应用程序通过对源飞地执行 ECALL 并传入目标飞地的飞地 ID,在源飞地和目标飞地之间发起会话。在接收到目标 enclave 的 enclave id 后,源 enclave 对核心不可信代码执行 OCALL,然后对目标 enclave 执行 ECALL 以交换使用 ECDH 密钥交换协议建立会话所需的消息。
我正在尝试在从两个不同应用程序创建的两个 enclave 之间执行本地证明。
为 Linux here 提供的示例代码创建了 3 个不同的飞地,然后在它们之间建立安全连接。但是这些飞地都是由同一个应用程序创建的,因此知道所有飞地 ID。
如果两个不同的应用程序正在创建自己的应该相互通信的 enclave,那么源 enclave 将如何知道目标 enclave 的 ID?该 ID 是否必须以 "general" 方式 (IPC) 从一个应用程序传输到 enclave?
我尝试了一些简单的测试,方法是启动目标飞地并打印其 ID:“26ce00000002”
然后我在本地证明示例中使用此 ID 尝试连接到此 运行 目标飞地:
uint64_t wrapper(const char *c) {
errno = 0;
uint64_t result = strtoull(c, NULL, 16);
if (errno == EINVAL) {
cout << "WRONG NUMBER" << endl;
} else if (errno == ERANGE) {
cout << "Too big\n";
}
return result;
}
uint32_t load_enclaves() {
uint32_t enclave_temp_no;
int ret, launch_token_updated;
sgx_launch_token_t launch_token;
enclave_temp_no = 0;
ret = sgx_create_enclave(ENCLAVE1_PATH, SGX_DEBUG_FLAG, &launch_token, &launch_token_updated, &e1_enclave_id, NULL);
if (ret != SGX_SUCCESS) {
return ret;
}
enclave_temp_no++;
g_enclave_id_map.insert(std::pair<sgx_enclave_id_t, uint32_t>(e1_enclave_id, enclave_temp_no));
const char *test = "26ce00000002";
e2_enclave_id = wrapper(test);
enclave_temp_no++;
g_enclave_id_map.insert(std::pair<sgx_enclave_id_t, uint32_t>(e2_enclave_id, enclave_temp_no));
return SGX_SUCCESS;
}
int main(int argc, char **argv) {
uint32_t ret_status;
sgx_status_t status;
if(load_enclaves() != SGX_SUCCESS) {
printf("\nLoad Enclave Failure");
}
printf("\nAvaliable Enclaves");
printf("\nEnclave1 - EnclaveID %lx",e1_enclave_id);
printf("\nEnclave2 - EnclaveID %lx",e2_enclave_id);
do {
//Test Create session between Enclave1(Source) and Enclave2(Destination)
status = Enclave1_test_create_session(e1_enclave_id, &ret_status, e1_enclave_id, e2_enclave_id);
if (status!=SGX_SUCCESS)
{
printf("Enclave1_test_create_session Ecall failed: Error status code is %x", status);
print_error_message(status);
break;
}
else
{
if(ret_status==0)
{
printf("\n\nSecure Channel Establishment between Source (E1) and Destination (E2) Enclaves successful !!!");
}
else
{
printf("\nSession establishment and key exchange failure between Source (E1) and Destination (E2): Error return status is %x\n", ret_status);
break;
}
}
当使用源 enclave 执行本地证明程序时,我收到 "SGX_ERROR_INVALID_ENCLAVE_ID" 错误?这个错误不是由本地证明示例程序引发的,而是来自 SGX 库中的某个地方,我不知道为什么因为目标飞地仍然是 运行,因此 ID 应该存在!?
我们不需要安全连接来交换飞地 ID。应用程序可以将飞地 ID 与飞地名称一起存储在注册表或磁盘上,飞地名称可以由相应的应用程序检索以获得所需飞地的 ID。然后,应用程序通过对源飞地执行 ECALL 并传入目标飞地的飞地 ID,在源飞地和目标飞地之间发起会话。在接收到目标 enclave 的 enclave id 后,源 enclave 对核心不可信代码执行 OCALL,然后对目标 enclave 执行 ECALL 以交换使用 ECDH 密钥交换协议建立会话所需的消息。