[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,12 @@
|
|||
<EnclaveConfiguration>
|
||||
<ProdID>0</ProdID>
|
||||
<ISVSVN>0</ISVSVN>
|
||||
<StackMaxSize>0x40000</StackMaxSize>
|
||||
<HeapMaxSize>0x100000</HeapMaxSize>
|
||||
<TCSNum>1</TCSNum>
|
||||
<TCSPolicy>1</TCSPolicy>
|
||||
<!-- Recommend changing 'DisableDebug' to 1 to make the enclave undebuggable for enclave release -->
|
||||
<DisableDebug>0</DisableDebug>
|
||||
<MiscSelect>0</MiscSelect>
|
||||
<MiscMask>0xFFFFFFFF</MiscMask>
|
||||
</EnclaveConfiguration>
|
||||
|
|
@ -0,0 +1,367 @@
|
|||
/*
|
||||
* Copyright (C) 2011-2018 Intel Corporation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Intel Corporation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
// Enclave1.cpp : Defines the exported functions for the .so application
|
||||
#include "sgx_eid.h"
|
||||
#include "Enclave1_t.h"
|
||||
#include "EnclaveMessageExchange.h"
|
||||
#include "error_codes.h"
|
||||
#include "Utility_E1.h"
|
||||
#include "sgx_thread.h"
|
||||
#include "sgx_dh.h"
|
||||
#include <map>
|
||||
|
||||
#define UNUSED(val) (void)(val)
|
||||
|
||||
std::map<sgx_enclave_id_t, dh_session_t>g_src_session_info_map;
|
||||
|
||||
static uint32_t e1_foo1_wrapper(ms_in_msg_exchange_t *ms, size_t param_lenth, char** resp_buffer, size_t* resp_length);
|
||||
|
||||
//Function pointer table containing the list of functions that the enclave exposes
|
||||
const struct {
|
||||
size_t num_funcs;
|
||||
const void* table[1];
|
||||
} func_table = {
|
||||
1,
|
||||
{
|
||||
(const void*)e1_foo1_wrapper,
|
||||
}
|
||||
};
|
||||
|
||||
//Makes use of the sample code function to establish a secure channel with the destination enclave (Test Vector)
|
||||
uint32_t test_create_session(sgx_enclave_id_t src_enclave_id,
|
||||
sgx_enclave_id_t dest_enclave_id)
|
||||
{
|
||||
ATTESTATION_STATUS ke_status = SUCCESS;
|
||||
dh_session_t dest_session_info;
|
||||
|
||||
//Core reference code function for creating a session
|
||||
ke_status = create_session(src_enclave_id, dest_enclave_id, &dest_session_info);
|
||||
|
||||
return ke_status;
|
||||
}
|
||||
|
||||
//Makes use of the sample code function to do an enclave to enclave call (Test Vector)
|
||||
uint32_t test_enclave_to_enclave_call(sgx_enclave_id_t src_enclave_id,
|
||||
sgx_enclave_id_t dest_enclave_id)
|
||||
{
|
||||
ATTESTATION_STATUS ke_status = SUCCESS;
|
||||
uint32_t var1,var2;
|
||||
uint32_t target_fn_id, msg_type;
|
||||
char* marshalled_inp_buff;
|
||||
size_t marshalled_inp_buff_len;
|
||||
char* out_buff;
|
||||
size_t out_buff_len;
|
||||
dh_session_t *dest_session_info;
|
||||
size_t max_out_buff_size;
|
||||
char* retval;
|
||||
|
||||
var1 = 0x4;
|
||||
var2 = 0x5;
|
||||
target_fn_id = 0;
|
||||
msg_type = ENCLAVE_TO_ENCLAVE_CALL;
|
||||
max_out_buff_size = 50;
|
||||
|
||||
//Marshals the input parameters for calling function foo1 in Enclave2 into a input buffer
|
||||
ke_status = marshal_input_parameters_e2_foo1(target_fn_id, msg_type, var1, var2, &marshalled_inp_buff, &marshalled_inp_buff_len);
|
||||
if(ke_status != SUCCESS)
|
||||
{
|
||||
return ke_status;
|
||||
}
|
||||
|
||||
//Search the map for the session information associated with the destination enclave id of Enclave2 passed in
|
||||
std::map<sgx_enclave_id_t, dh_session_t>::iterator it = g_src_session_info_map.find(dest_enclave_id);
|
||||
if(it != g_src_session_info_map.end())
|
||||
{
|
||||
dest_session_info = &it->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
SAFE_FREE(marshalled_inp_buff);
|
||||
return INVALID_SESSION;
|
||||
}
|
||||
|
||||
//Core Reference Code function
|
||||
ke_status = send_request_receive_response(src_enclave_id, dest_enclave_id, dest_session_info, marshalled_inp_buff,
|
||||
marshalled_inp_buff_len, max_out_buff_size, &out_buff, &out_buff_len);
|
||||
|
||||
|
||||
if(ke_status != SUCCESS)
|
||||
{
|
||||
SAFE_FREE(marshalled_inp_buff);
|
||||
SAFE_FREE(out_buff);
|
||||
return ke_status;
|
||||
}
|
||||
|
||||
//Un-marshal the return value and output parameters from foo1 of Enclave 2
|
||||
ke_status = unmarshal_retval_and_output_parameters_e2_foo1(out_buff, &retval);
|
||||
if(ke_status != SUCCESS)
|
||||
{
|
||||
SAFE_FREE(marshalled_inp_buff);
|
||||
SAFE_FREE(out_buff);
|
||||
return ke_status;
|
||||
}
|
||||
|
||||
SAFE_FREE(marshalled_inp_buff);
|
||||
SAFE_FREE(out_buff);
|
||||
SAFE_FREE(retval);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
//Makes use of the sample code function to do a generic secret message exchange (Test Vector)
|
||||
uint32_t test_message_exchange(sgx_enclave_id_t src_enclave_id,
|
||||
sgx_enclave_id_t dest_enclave_id)
|
||||
{
|
||||
ATTESTATION_STATUS ke_status = SUCCESS;
|
||||
uint32_t target_fn_id, msg_type;
|
||||
char* marshalled_inp_buff;
|
||||
size_t marshalled_inp_buff_len;
|
||||
char* out_buff;
|
||||
size_t out_buff_len;
|
||||
dh_session_t *dest_session_info;
|
||||
size_t max_out_buff_size;
|
||||
char* secret_response;
|
||||
uint32_t secret_data;
|
||||
|
||||
target_fn_id = 0;
|
||||
msg_type = MESSAGE_EXCHANGE;
|
||||
max_out_buff_size = 50;
|
||||
secret_data = 0x12345678; //Secret Data here is shown only for purpose of demonstration.
|
||||
|
||||
//Marshals the secret data into a buffer
|
||||
ke_status = marshal_message_exchange_request(target_fn_id, msg_type, secret_data, &marshalled_inp_buff, &marshalled_inp_buff_len);
|
||||
if(ke_status != SUCCESS)
|
||||
{
|
||||
return ke_status;
|
||||
}
|
||||
//Search the map for the session information associated with the destination enclave id passed in
|
||||
std::map<sgx_enclave_id_t, dh_session_t>::iterator it = g_src_session_info_map.find(dest_enclave_id);
|
||||
if(it != g_src_session_info_map.end())
|
||||
{
|
||||
dest_session_info = &it->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
SAFE_FREE(marshalled_inp_buff);
|
||||
return INVALID_SESSION;
|
||||
}
|
||||
|
||||
//Core Reference Code function
|
||||
ke_status = send_request_receive_response(src_enclave_id, dest_enclave_id, dest_session_info, marshalled_inp_buff,
|
||||
marshalled_inp_buff_len, max_out_buff_size, &out_buff, &out_buff_len);
|
||||
if(ke_status != SUCCESS)
|
||||
{
|
||||
SAFE_FREE(marshalled_inp_buff);
|
||||
SAFE_FREE(out_buff);
|
||||
return ke_status;
|
||||
}
|
||||
|
||||
//Un-marshal the secret response data
|
||||
ke_status = umarshal_message_exchange_response(out_buff, &secret_response);
|
||||
if(ke_status != SUCCESS)
|
||||
{
|
||||
SAFE_FREE(marshalled_inp_buff);
|
||||
SAFE_FREE(out_buff);
|
||||
return ke_status;
|
||||
}
|
||||
|
||||
SAFE_FREE(marshalled_inp_buff);
|
||||
SAFE_FREE(out_buff);
|
||||
SAFE_FREE(secret_response);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
//Makes use of the sample code function to close a current session
|
||||
uint32_t test_close_session(sgx_enclave_id_t src_enclave_id,
|
||||
sgx_enclave_id_t dest_enclave_id)
|
||||
{
|
||||
dh_session_t dest_session_info;
|
||||
ATTESTATION_STATUS ke_status = SUCCESS;
|
||||
//Search the map for the session information associated with the destination enclave id passed in
|
||||
std::map<sgx_enclave_id_t, dh_session_t>::iterator it = g_src_session_info_map.find(dest_enclave_id);
|
||||
if(it != g_src_session_info_map.end())
|
||||
{
|
||||
dest_session_info = it->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//Core reference code function for closing a session
|
||||
ke_status = close_session(src_enclave_id, dest_enclave_id);
|
||||
|
||||
//Erase the session information associated with the destination enclave id
|
||||
g_src_session_info_map.erase(dest_enclave_id);
|
||||
return ke_status;
|
||||
}
|
||||
|
||||
//Function that is used to verify the trust of the other enclave
|
||||
//Each enclave can have its own way verifying the peer enclave identity
|
||||
extern "C" uint32_t verify_peer_enclave_trust(sgx_dh_session_enclave_identity_t* peer_enclave_identity)
|
||||
{
|
||||
if(!peer_enclave_identity)
|
||||
{
|
||||
return INVALID_PARAMETER_ERROR;
|
||||
}
|
||||
if(peer_enclave_identity->isv_prod_id != 0 || !(peer_enclave_identity->attributes.flags & SGX_FLAGS_INITTED))
|
||||
// || peer_enclave_identity->attributes.xfrm !=3)// || peer_enclave_identity->mr_signer != xx //TODO: To be hardcoded with values to check
|
||||
{
|
||||
return ENCLAVE_TRUST_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Dispatcher function that calls the approriate enclave function based on the function id
|
||||
//Each enclave can have its own way of dispatching the calls from other enclave
|
||||
extern "C" uint32_t enclave_to_enclave_call_dispatcher(char* decrypted_data,
|
||||
size_t decrypted_data_length,
|
||||
char** resp_buffer,
|
||||
size_t* resp_length)
|
||||
{
|
||||
ms_in_msg_exchange_t *ms;
|
||||
uint32_t (*fn1)(ms_in_msg_exchange_t *ms, size_t, char**, size_t*);
|
||||
if(!decrypted_data || !resp_length)
|
||||
{
|
||||
return INVALID_PARAMETER_ERROR;
|
||||
}
|
||||
ms = (ms_in_msg_exchange_t *)decrypted_data;
|
||||
if(ms->target_fn_id >= func_table.num_funcs)
|
||||
{
|
||||
return INVALID_PARAMETER_ERROR;
|
||||
}
|
||||
fn1 = (uint32_t (*)(ms_in_msg_exchange_t*, size_t, char**, size_t*))func_table.table[ms->target_fn_id];
|
||||
return fn1(ms, decrypted_data_length, resp_buffer, resp_length);
|
||||
}
|
||||
|
||||
//Operates on the input secret and generates the output secret
|
||||
uint32_t get_message_exchange_response(uint32_t inp_secret_data)
|
||||
{
|
||||
uint32_t secret_response;
|
||||
|
||||
//User should use more complex encryption method to protect their secret, below is just a simple example
|
||||
secret_response = inp_secret_data & 0x11111111;
|
||||
|
||||
return secret_response;
|
||||
|
||||
}
|
||||
|
||||
//Generates the response from the request message
|
||||
extern "C" uint32_t message_exchange_response_generator(char* decrypted_data,
|
||||
char** resp_buffer,
|
||||
size_t* resp_length)
|
||||
{
|
||||
ms_in_msg_exchange_t *ms;
|
||||
uint32_t inp_secret_data;
|
||||
uint32_t out_secret_data;
|
||||
if(!decrypted_data || !resp_length)
|
||||
{
|
||||
return INVALID_PARAMETER_ERROR;
|
||||
}
|
||||
ms = (ms_in_msg_exchange_t *)decrypted_data;
|
||||
|
||||
if(umarshal_message_exchange_request(&inp_secret_data,ms) != SUCCESS)
|
||||
return ATTESTATION_ERROR;
|
||||
|
||||
out_secret_data = get_message_exchange_response(inp_secret_data);
|
||||
|
||||
if(marshal_message_exchange_response(resp_buffer, resp_length, out_secret_data) != SUCCESS)
|
||||
return MALLOC_ERROR;
|
||||
|
||||
return SUCCESS;
|
||||
|
||||
}
|
||||
|
||||
|
||||
static uint32_t e1_foo1(external_param_struct_t *p_struct_var)
|
||||
{
|
||||
if(!p_struct_var)
|
||||
{
|
||||
return INVALID_PARAMETER_ERROR;
|
||||
}
|
||||
(p_struct_var->var1)++;
|
||||
(p_struct_var->var2)++;
|
||||
(p_struct_var->p_internal_struct->ivar1)++;
|
||||
(p_struct_var->p_internal_struct->ivar2)++;
|
||||
|
||||
return (p_struct_var->var1 + p_struct_var->var2 + p_struct_var->p_internal_struct->ivar1 + p_struct_var->p_internal_struct->ivar2);
|
||||
}
|
||||
|
||||
//Function which is executed on request from the source enclave
|
||||
static uint32_t e1_foo1_wrapper(ms_in_msg_exchange_t *ms,
|
||||
size_t param_lenth,
|
||||
char** resp_buffer,
|
||||
size_t* resp_length)
|
||||
{
|
||||
UNUSED(param_lenth);
|
||||
|
||||
uint32_t ret;
|
||||
size_t len_data, len_ptr_data;
|
||||
external_param_struct_t *p_struct_var;
|
||||
internal_param_struct_t internal_struct_var;
|
||||
|
||||
if(!ms || !resp_length)
|
||||
{
|
||||
return INVALID_PARAMETER_ERROR;
|
||||
}
|
||||
|
||||
p_struct_var = (external_param_struct_t*)malloc(sizeof(external_param_struct_t));
|
||||
if(!p_struct_var)
|
||||
return MALLOC_ERROR;
|
||||
|
||||
p_struct_var->p_internal_struct = &internal_struct_var;
|
||||
|
||||
if(unmarshal_input_parameters_e1_foo1(p_struct_var, ms) != SUCCESS)//can use the stack
|
||||
{
|
||||
SAFE_FREE(p_struct_var);
|
||||
return ATTESTATION_ERROR;
|
||||
}
|
||||
|
||||
ret = e1_foo1(p_struct_var);
|
||||
|
||||
len_data = sizeof(external_param_struct_t) - sizeof(p_struct_var->p_internal_struct);
|
||||
len_ptr_data = sizeof(internal_struct_var);
|
||||
|
||||
if(marshal_retval_and_output_parameters_e1_foo1(resp_buffer, resp_length, ret, p_struct_var, len_data, len_ptr_data) != SUCCESS)
|
||||
{
|
||||
SAFE_FREE(p_struct_var);
|
||||
return MALLOC_ERROR;
|
||||
}
|
||||
SAFE_FREE(p_struct_var);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright (C) 2011-2018 Intel Corporation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Intel Corporation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
enclave {
|
||||
include "sgx_eid.h"
|
||||
from "../LocalAttestationCode/LocalAttestationCode.edl" import *;
|
||||
from "sgx_tstdc.edl" import *;
|
||||
trusted{
|
||||
public uint32_t test_create_session(sgx_enclave_id_t src_enclave_id, sgx_enclave_id_t dest_enclave_id);
|
||||
public uint32_t test_enclave_to_enclave_call(sgx_enclave_id_t src_enclave_id, sgx_enclave_id_t dest_enclave_id);
|
||||
public uint32_t test_message_exchange(sgx_enclave_id_t src_enclave_id, sgx_enclave_id_t dest_enclave_id);
|
||||
public uint32_t test_close_session(sgx_enclave_id_t src_enclave_id, sgx_enclave_id_t dest_enclave_id);
|
||||
};
|
||||
|
||||
};
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
Enclave1.so
|
||||
{
|
||||
global:
|
||||
g_global_data_sim;
|
||||
g_global_data;
|
||||
enclave_entry;
|
||||
g_peak_heap_used;
|
||||
local:
|
||||
*;
|
||||
};
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
-----BEGIN RSA PRIVATE KEY-----
|
||||
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
|
||||
-----END RSA PRIVATE KEY-----
|
||||
|
|
@ -0,0 +1,222 @@
|
|||
/*
|
||||
* Copyright (C) 2011-2018 Intel Corporation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Intel Corporation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sgx_eid.h"
|
||||
#include "EnclaveMessageExchange.h"
|
||||
#include "error_codes.h"
|
||||
#include "Utility_E1.h"
|
||||
#include "stdlib.h"
|
||||
#include "string.h"
|
||||
|
||||
uint32_t marshal_input_parameters_e2_foo1(uint32_t target_fn_id, uint32_t msg_type, uint32_t var1, uint32_t var2, char** marshalled_buff, size_t* marshalled_buff_len)
|
||||
{
|
||||
ms_in_msg_exchange_t *ms;
|
||||
size_t param_len, ms_len;
|
||||
char *temp_buff;
|
||||
|
||||
param_len = sizeof(var1)+sizeof(var2);
|
||||
temp_buff = (char*)malloc(param_len);
|
||||
if(!temp_buff)
|
||||
return MALLOC_ERROR;
|
||||
|
||||
memcpy(temp_buff,&var1,sizeof(var1));
|
||||
memcpy(temp_buff+sizeof(var1),&var2,sizeof(var2));
|
||||
ms_len = sizeof(ms_in_msg_exchange_t) + param_len;
|
||||
ms = (ms_in_msg_exchange_t *)malloc(ms_len);
|
||||
if(!ms)
|
||||
{
|
||||
SAFE_FREE(temp_buff);
|
||||
return MALLOC_ERROR;
|
||||
}
|
||||
ms->msg_type = msg_type;
|
||||
ms->target_fn_id = target_fn_id;
|
||||
ms->inparam_buff_len = (uint32_t)param_len;
|
||||
memcpy(&ms->inparam_buff, temp_buff, param_len);
|
||||
*marshalled_buff = (char*)ms;
|
||||
*marshalled_buff_len = ms_len;
|
||||
SAFE_FREE(temp_buff);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
uint32_t unmarshal_retval_and_output_parameters_e2_foo1(char* out_buff, char** retval)
|
||||
{
|
||||
size_t retval_len;
|
||||
ms_out_msg_exchange_t *ms;
|
||||
if(!out_buff)
|
||||
return INVALID_PARAMETER_ERROR;
|
||||
ms = (ms_out_msg_exchange_t *)out_buff;
|
||||
retval_len = ms->retval_len;
|
||||
*retval = (char*)malloc(retval_len);
|
||||
if(!*retval)
|
||||
return MALLOC_ERROR;
|
||||
|
||||
memcpy(*retval, ms->ret_outparam_buff, retval_len);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
uint32_t unmarshal_input_parameters_e1_foo1(external_param_struct_t *pstruct, ms_in_msg_exchange_t* ms)
|
||||
{
|
||||
char* buff;
|
||||
size_t len;
|
||||
if(!pstruct || !ms)
|
||||
return INVALID_PARAMETER_ERROR;
|
||||
|
||||
buff = ms->inparam_buff;
|
||||
len = ms->inparam_buff_len;
|
||||
if(len != (sizeof(pstruct->var1)+sizeof(pstruct->var2)+sizeof(pstruct->p_internal_struct->ivar1)+sizeof(pstruct->p_internal_struct->ivar2)))
|
||||
return ATTESTATION_ERROR;
|
||||
|
||||
memcpy(&pstruct->var1, buff, sizeof(pstruct->var1));
|
||||
memcpy(&pstruct->var2, buff + sizeof(pstruct->var1), sizeof(pstruct->var2));
|
||||
memcpy(&pstruct->p_internal_struct->ivar1, buff+(sizeof(pstruct->var1)+sizeof(pstruct->var2)), sizeof(pstruct->p_internal_struct->ivar1));
|
||||
memcpy(&pstruct->p_internal_struct->ivar2, buff+(sizeof(pstruct->var1)+sizeof(pstruct->var2)+sizeof(pstruct->p_internal_struct->ivar1)), sizeof(pstruct->p_internal_struct->ivar2));
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
uint32_t marshal_retval_and_output_parameters_e1_foo1(char** resp_buffer, size_t* resp_length, uint32_t retval, external_param_struct_t *p_struct_var, size_t len_data, size_t len_ptr_data)
|
||||
{
|
||||
ms_out_msg_exchange_t *ms;
|
||||
size_t param_len, ms_len, ret_param_len;;
|
||||
char *temp_buff;
|
||||
int* addr;
|
||||
char* struct_data;
|
||||
size_t retval_len;
|
||||
|
||||
if(!resp_length || !p_struct_var)
|
||||
return INVALID_PARAMETER_ERROR;
|
||||
|
||||
retval_len = sizeof(retval);
|
||||
struct_data = (char*)p_struct_var;
|
||||
param_len = len_data + len_ptr_data;
|
||||
ret_param_len = param_len + retval_len;
|
||||
addr = *(int **)(struct_data + len_data);
|
||||
temp_buff = (char*)malloc(ret_param_len);
|
||||
if(!temp_buff)
|
||||
return MALLOC_ERROR;
|
||||
|
||||
memcpy(temp_buff, &retval, sizeof(retval));
|
||||
memcpy(temp_buff + sizeof(retval), struct_data, len_data);
|
||||
memcpy(temp_buff + sizeof(retval) + len_data, addr, len_ptr_data);
|
||||
ms_len = sizeof(ms_out_msg_exchange_t) + ret_param_len;
|
||||
ms = (ms_out_msg_exchange_t *)malloc(ms_len);
|
||||
if(!ms)
|
||||
{
|
||||
SAFE_FREE(temp_buff);
|
||||
return MALLOC_ERROR;
|
||||
}
|
||||
ms->retval_len = (uint32_t)retval_len;
|
||||
ms->ret_outparam_buff_len = (uint32_t)ret_param_len;
|
||||
memcpy(&ms->ret_outparam_buff, temp_buff, ret_param_len);
|
||||
*resp_buffer = (char*)ms;
|
||||
*resp_length = ms_len;
|
||||
|
||||
SAFE_FREE(temp_buff);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
uint32_t marshal_message_exchange_request(uint32_t target_fn_id, uint32_t msg_type, uint32_t secret_data, char** marshalled_buff, size_t* marshalled_buff_len)
|
||||
{
|
||||
ms_in_msg_exchange_t *ms;
|
||||
size_t secret_data_len, ms_len;
|
||||
if(!marshalled_buff_len)
|
||||
return INVALID_PARAMETER_ERROR;
|
||||
secret_data_len = sizeof(secret_data);
|
||||
ms_len = sizeof(ms_in_msg_exchange_t) + secret_data_len;
|
||||
ms = (ms_in_msg_exchange_t *)malloc(ms_len);
|
||||
if(!ms)
|
||||
return MALLOC_ERROR;
|
||||
|
||||
ms->msg_type = msg_type;
|
||||
ms->target_fn_id = target_fn_id;
|
||||
ms->inparam_buff_len = (uint32_t)secret_data_len;
|
||||
memcpy(&ms->inparam_buff, &secret_data, secret_data_len);
|
||||
*marshalled_buff = (char*)ms;
|
||||
*marshalled_buff_len = ms_len;
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
uint32_t umarshal_message_exchange_request(uint32_t* inp_secret_data, ms_in_msg_exchange_t* ms)
|
||||
{
|
||||
char* buff;
|
||||
size_t len;
|
||||
if(!inp_secret_data || !ms)
|
||||
return INVALID_PARAMETER_ERROR;
|
||||
buff = ms->inparam_buff;
|
||||
len = ms->inparam_buff_len;
|
||||
if(len != sizeof(uint32_t))
|
||||
return ATTESTATION_ERROR;
|
||||
|
||||
memcpy(inp_secret_data, buff, sizeof(uint32_t));
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
uint32_t marshal_message_exchange_response(char** resp_buffer, size_t* resp_length, uint32_t secret_response)
|
||||
{
|
||||
ms_out_msg_exchange_t *ms;
|
||||
size_t secret_response_len, ms_len;
|
||||
size_t retval_len, ret_param_len;
|
||||
if(!resp_length)
|
||||
return INVALID_PARAMETER_ERROR;
|
||||
secret_response_len = sizeof(secret_response);
|
||||
retval_len = secret_response_len;
|
||||
ret_param_len = secret_response_len;
|
||||
ms_len = sizeof(ms_out_msg_exchange_t) + ret_param_len;
|
||||
ms = (ms_out_msg_exchange_t *)malloc(ms_len);
|
||||
if(!ms)
|
||||
return MALLOC_ERROR;
|
||||
|
||||
ms->retval_len = (uint32_t)retval_len;
|
||||
ms->ret_outparam_buff_len = (uint32_t)ret_param_len;
|
||||
memcpy(&ms->ret_outparam_buff, &secret_response, secret_response_len);
|
||||
*resp_buffer = (char*)ms;
|
||||
*resp_length = ms_len;
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
uint32_t umarshal_message_exchange_response(char* out_buff, char** secret_response)
|
||||
{
|
||||
size_t retval_len;
|
||||
ms_out_msg_exchange_t *ms;
|
||||
if(!out_buff)
|
||||
return INVALID_PARAMETER_ERROR;
|
||||
ms = (ms_out_msg_exchange_t *)out_buff;
|
||||
retval_len = ms->retval_len;
|
||||
*secret_response = (char*)malloc(retval_len);
|
||||
if(!*secret_response)
|
||||
{
|
||||
return MALLOC_ERROR;
|
||||
}
|
||||
memcpy(*secret_response, ms->ret_outparam_buff, retval_len);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Copyright (C) 2011-2018 Intel Corporation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Intel Corporation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef UTILITY_E1_H__
|
||||
#define UTILITY_E1_H__
|
||||
|
||||
#include "stdint.h"
|
||||
|
||||
typedef struct _internal_param_struct_t
|
||||
{
|
||||
uint32_t ivar1;
|
||||
uint32_t ivar2;
|
||||
}internal_param_struct_t;
|
||||
|
||||
typedef struct _external_param_struct_t
|
||||
{
|
||||
uint32_t var1;
|
||||
uint32_t var2;
|
||||
internal_param_struct_t *p_internal_struct;
|
||||
}external_param_struct_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
uint32_t marshal_input_parameters_e2_foo1(uint32_t target_fn_id, uint32_t msg_type, uint32_t var1, uint32_t var2, char** marshalled_buff, size_t* marshalled_buff_len);
|
||||
uint32_t unmarshal_retval_and_output_parameters_e2_foo1(char* out_buff, char** retval);
|
||||
uint32_t unmarshal_input_parameters_e1_foo1(external_param_struct_t *pstruct, ms_in_msg_exchange_t* ms);
|
||||
uint32_t marshal_retval_and_output_parameters_e1_foo1(char** resp_buffer, size_t* resp_length, uint32_t retval, external_param_struct_t *p_struct_var, size_t len_data, size_t len_ptr_data);
|
||||
uint32_t marshal_message_exchange_request(uint32_t target_fn_id, uint32_t msg_type, uint32_t secret_data, char** marshalled_buff, size_t* marshalled_buff_len);
|
||||
uint32_t umarshal_message_exchange_request(uint32_t* inp_secret_data, ms_in_msg_exchange_t* ms);
|
||||
uint32_t marshal_message_exchange_response(char** resp_buffer, size_t* resp_length, uint32_t secret_response);
|
||||
uint32_t umarshal_message_exchange_response(char* out_buff, char** secret_response);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue