[Assignment-7] add SGX sample code from VM
All checks were successful
Latex Build / build-latex (Assignment 4 - Protokollsicherheit (Praxis)) (push) Successful in 1m2s
Latex Build / build-latex (Assignment 5 - Software Security - Teil 1) (push) Successful in 1m3s
Latex Build / build-latex (Assignment 6 - Software Security - Teil 2) (push) Successful in 1m0s
Latex Build / build-latex (Assignment 4 - Protokollsicherheit (Praxis)) (pull_request) Successful in 30s
Latex Build / build-latex (Assignment 5 - Software Security - Teil 1) (pull_request) Successful in 10s
Latex Build / build-latex (Assignment 6 - Software Security - Teil 2) (pull_request) Successful in 8s
All checks were successful
Latex Build / build-latex (Assignment 4 - Protokollsicherheit (Praxis)) (push) Successful in 1m2s
Latex Build / build-latex (Assignment 5 - Software Security - Teil 1) (push) Successful in 1m3s
Latex Build / build-latex (Assignment 6 - Software Security - Teil 2) (push) Successful in 1m0s
Latex Build / build-latex (Assignment 4 - Protokollsicherheit (Praxis)) (pull_request) Successful in 30s
Latex Build / build-latex (Assignment 5 - Software Security - Teil 1) (pull_request) Successful in 10s
Latex Build / build-latex (Assignment 6 - Software Security - Teil 2) (pull_request) Successful in 8s
This commit is contained in:
parent
5616ddc4e5
commit
ba8e969470
163 changed files with 24030 additions and 0 deletions
|
|
@ -0,0 +1,110 @@
|
|||
#include "Enclave.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace util;
|
||||
using namespace std;
|
||||
|
||||
Enclave* Enclave::instance = NULL;
|
||||
|
||||
Enclave::Enclave() {}
|
||||
|
||||
Enclave* Enclave::getInstance() {
|
||||
if (instance == NULL) {
|
||||
instance = new Enclave();
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
Enclave::~Enclave() {
|
||||
int ret = -1;
|
||||
|
||||
if (INT_MAX != context) {
|
||||
int ret_save = -1;
|
||||
ret = enclave_ra_close(enclave_id, &status, context);
|
||||
if (SGX_SUCCESS != ret || status) {
|
||||
ret = -1;
|
||||
Log("Error, call enclave_ra_close fail", log::error);
|
||||
} else {
|
||||
// enclave_ra_close was successful, let's restore the value that
|
||||
// led us to this point in the code.
|
||||
ret = ret_save;
|
||||
}
|
||||
|
||||
Log("Call enclave_ra_close success");
|
||||
}
|
||||
|
||||
sgx_destroy_enclave(enclave_id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
sgx_status_t Enclave::createEnclave() {
|
||||
sgx_status_t ret;
|
||||
int launch_token_update = 0;
|
||||
int enclave_lost_retry_time = 1;
|
||||
sgx_launch_token_t launch_token = {0};
|
||||
|
||||
memset(&launch_token, 0, sizeof(sgx_launch_token_t));
|
||||
|
||||
do {
|
||||
ret = sgx_create_enclave(this->enclave_path,
|
||||
SGX_DEBUG_FLAG,
|
||||
&launch_token,
|
||||
&launch_token_update,
|
||||
&this->enclave_id, NULL);
|
||||
|
||||
if (SGX_SUCCESS != ret) {
|
||||
Log("Error, call sgx_create_enclave fail", log::error);
|
||||
print_error_message(ret);
|
||||
break;
|
||||
} else {
|
||||
Log("Call sgx_create_enclave success");
|
||||
|
||||
ret = enclave_init_ra(this->enclave_id,
|
||||
&this->status,
|
||||
false,
|
||||
&this->context);
|
||||
}
|
||||
|
||||
} while (SGX_ERROR_ENCLAVE_LOST == ret && enclave_lost_retry_time--);
|
||||
|
||||
if (ret == SGX_SUCCESS)
|
||||
Log("Enclave created, ID: %llx", this->enclave_id);
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
sgx_enclave_id_t Enclave::getID() {
|
||||
return this->enclave_id;
|
||||
}
|
||||
|
||||
sgx_status_t Enclave::getStatus() {
|
||||
return this->status;
|
||||
}
|
||||
|
||||
sgx_ra_context_t Enclave::getContext() {
|
||||
return this->context;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
#ifndef ENCLAVE_H
|
||||
#define ENCLAVE_H
|
||||
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "LogBase.h"
|
||||
#include "UtilityFunctions.h"
|
||||
#include "isv_enclave_u.h"
|
||||
|
||||
// Needed to call untrusted key exchange library APIs, i.e. sgx_ra_proc_msg2.
|
||||
#include "sgx_ukey_exchange.h"
|
||||
|
||||
// Needed to query extended epid group id.
|
||||
#include "sgx_uae_service.h"
|
||||
|
||||
class Enclave {
|
||||
|
||||
public:
|
||||
static Enclave* getInstance();
|
||||
virtual ~Enclave();
|
||||
sgx_status_t createEnclave();
|
||||
sgx_enclave_id_t getID();
|
||||
sgx_status_t getStatus();
|
||||
sgx_ra_context_t getContext();
|
||||
|
||||
private:
|
||||
Enclave();
|
||||
static Enclave *instance;
|
||||
const char *enclave_path = "isv_enclave.signed.so";
|
||||
sgx_enclave_id_t enclave_id;
|
||||
sgx_status_t status;
|
||||
sgx_ra_context_t context;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue