Error Loading Enclave: Couldn't open file with

2019-09-13 23:56发布

问题:

I'm trying to write a simple SGX project for a start. So I have this main host application routine that I've pretty much copied from Lars Richter's blog:

#define ENCLAVE_FILE _T("Enclave.signed.dll")
#include <tchar.h>
#include <cstdio>
#include "sgx_urts.h"
#include "Enclave_u.h"

int main()
{
    sgx_enclave_id_t   eid;
    sgx_status_t       ret = SGX_SUCCESS;
    sgx_launch_token_t token = { 0 };
    int updated = 0;

    ret = sgx_create_enclave(ENCLAVE_FILE, SGX_DEBUG_FLAG, &token, &updated, &eid, NULL);

    if (ret != SGX_SUCCESS) {
        printf("\nApp: error %#x, failed to create enclave.\n", ret);
    }


    scanf("\n");

    return 0;
}

It compiles fine (I'm using the Intel C++ 17.0 compiler with Visual Studio 2015) but it doesn't load the enclave. I get the following error message:

[sgx_create_enclavew ..\urts\win\urts.cpp:195] Couldn't open file with CreateFile()

App: error 0x200f, failed to create enclave.

回答1:

Go to app_test_save project setting. Under Debugging, change working directory to $(SolutionDir)Debug. This answer assumes that both projects app_test_save and enclave_test_save belong to the same solution.



回答2:

As Neil pointed out, sgx_create_enclave couldn't find the dll when the program was being run from within Visual Studio's debugger. It worked fine when I directly ran the executable in the "Debug" folder.

So a simple trick to make it work in both settings is to do the following:

#define ENCLAVE_FILE _T("../Debug/Enclave.signed.dll")


回答3:

According to this : https://software.intel.com/en-us/forums/intel-software-guard-extensions-intel-sgx/topic/623738

If you are using the Local SGX Debugger, Please make sure change the "current working directory" pointing to $(OutDir) instead of $(ProjectDir).

Configuration Properties --> Debugging --> Working Directory --> $(OutDir).



回答4:

Error is basically means it could not locate your .dll file. Do dir /a/s to find Enclave.signed.dll then change the name appropriately. When you create enclave it will generate signed.dll file. If your enclave name is Enclave12 then the DLL name is Enclave12.signed.dll. You fix this then you should be good to go.