/* * Copyright (C) 2011-2017 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_trts.h" #include "sgx_utils.h" #include "sgx_eid.h" #include "error_codes.h" #include "sgx_ecp_types.h" #include "sgx_thread.h" #include #include "sgx_dh.h" #include "dh_session_protocol.h" #include "sgx_tcrypto.h" #include "datatypes.h" #include "ProtobufSgxLATransforms_Inititator.h" #define MAX_SESSION_COUNT 16 #define SGX_CAST(type, item) ((type)(item)) #include // uint32_t session_ids[MAX_SESSION_COUNT] ; // Our enclave will not be doing LA with more than 1 decryptor enclave at a time. // We should not need this. //std::mapg_dest_session_info_map; dh_session_t global_session_info; // TODO: May be we need to store all previously assigned session IDs instead of just the counter; to prevent replay attacks - uint32_t global_session_id=0; uint32_t verify_peer_enclave_trust(sgx_dh_session_enclave_identity_t* peer_enclave_identity, uint8_t* expected_mr_enclave, uint8_t* expected_mr_signer) { int count=0; if(!peer_enclave_identity) return INVALID_PARAMETER_ERROR; sgx_measurement_t actual_mr_enclave = peer_enclave_identity->mr_enclave; sgx_measurement_t actual_mr_signer = peer_enclave_identity->mr_signer; /* for(count=0; count