使用英特尔SGX进行本地认证

时间:2017-01-07 10:11:51

标签: c++ sgx

我试图在两个不同应用程序创建的两个飞地之间执行本地证明。

Linux here提供的示例代码创建了3个不同的安全区,然后在它们之间建立安全连接。但是这些飞地都是由同一个应用程序创建的,因此它知道所有飞地ID。

如果两个不同的应用程序正在创建自己的飞地,这些飞地应该相互通信,那么源飞地将如何知道目的地飞地的ID?该ID是否必须从一个应用程序传输到一个" general"方式(IPC)?

我通过启动目的地飞地并打印其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;
            }
        }

当使用源包围区执行本地证明程序时,我收到&#34; SGX_ERROR_INVALID_ENCLAVE_ID&#34;错误?本地证明示例程序不会抛出此错误,但是来自SGX库中的某个地方,我不知道为什么因为目标空间仍在运行,因此ID应该存在!?

1 个答案:

答案 0 :(得分:3)

我们不需要安全连接来交换飞地id。应用程序可以将飞地id存储在注册表或光盘上以及可以由相应应用程序检索的包围区名称,以获得所需包围区的id。然后,应用程序通过在源区域中执行ECALL,传入源区域和目标区域之间的会话,传入目标区域的包围区域ID。在收到目的地飞地的飞地id后,源飞地对核心不可信代码进行OCALL,然后将ECALL进入目的地飞地,以使用ECDH密钥交换协议交换建立会话所需的消息。