/* * 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. * */ // Enclave2.cpp : Defines the exported functions for the DLL application #include "sgx_eid.h" #include "sgx_tcrypto.h" #include "Decryptor_t.h" #include "EnclaveMessageExchange.h" #include "error_codes.h" #include "Utility_Decryptor.h" #include "sgx_thread.h" #include "sgx_dh.h" #include #include "sgx_tcrypto.h" #include "LocalAttestationCode_t.h" #include "sgx_tseal.h" // internal-internal uint32_t create_ec_key_pair(sgx_ec256_public_t* pub_key, sgx_ec256_private_t* priv_key); void serialize_key_pair_to_string( sgx_ec256_public_t* pub_key, sgx_ec256_private_t* signing_priv_key, uint8_t* private_public_key_string); void deserialize_string_to_key_pair(uint8_t* private_public_key_string, sgx_ec256_public_t* pub_key, sgx_ec256_private_t* priv_key); uint32_t create_mitigator_header_value(uint8_t* signature_data, uint8_t* signature); uint32_t calculate_sealed_data_size( uint32_t input_size) ; uint32_t create_and_seal_ecdsa_signing_key_pair(__attribute__((unused)) sgx_ec256_public_t* pub_key, __attribute__((unused)) uint32_t* sealed_data_length, __attribute__((unused)) uint8_t* sealed_data); uint32_t unseal_and_restore_sealed_signing_key_pair(__attribute__((unused)) sgx_ec256_public_t* pub_key, uint8_t* sealed_data, size_t* sgx_sealed_data_length); uint32_t decrypt_verifiers_message_set_apache_mrsigner(uint8_t* ciphertext, uint8_t* tag); //uint32_t create_and_encrypt_mitigator_header_value(uint8_t* signature_data, uint8_t* signature, uint8_t* tag); uint32_t create_and_encrypt_mitigator_header_value(uint8_t* plaintext_sign_data_and_sign, uint8_t* encrypted_sign_data_and_sign, uint8_t* tag); uint32_t one_la_done=0; static sgx_ec256_public_t short_term_pub_key; static sgx_ec256_private_t short_term_priv_key; sgx_ec256_signature_t generated_signature; // TODO: remove sgx_measurement_t apache_mr_signer; // TODO: remove sgx_measurement_t verifier_mr_enclave; // TODO: remove static sgx_ec256_private_t signing_priv_key; extern "C" uint32_t verify_peer_enclave_trust(__attribute__((unused)) sgx_dh_session_enclave_identity_t* peer_enclave_identity) { uint32_t count; if(!peer_enclave_identity) { return INVALID_PARAMETER_ERROR; } if(one_la_done==0) { for(count=0; countmr_enclave.m[count]; memset(&(apache_mr_signer.m),0x0,SGX_HASH_SIZE); // "initialization" one_la_done=1; } else // apache enclave { sgx_measurement_t actual_mr_signer = peer_enclave_identity->mr_signer; // verifier's mrsigner // uint8_t expected_mr_signer[32] ={0xdf, 0xd7, 0x3b, 0x93, 0xea, 0x39, 0x02, 0x02, 0x3c, 0xd0, 0x52, 0x1a, 0xbd, 0x00, 0xaf, 0xb9, 0xa6, 0x54, 0x57, 0x3e, 0xe5, 0xef, 0x36, 0xf4, 0x8c, 0xc2, 0x4d, 0x92, 0x70, 0xae, 0xd4, 0x7c}; int count; for(count=0; countgx[counter]; for(counter=SGX_ECP256_KEY_SIZE;counter<2*SGX_ECP256_KEY_SIZE; counter++) *(private_public_key_string+counter)=pub_key->gy[counter-SGX_ECP256_KEY_SIZE]; } if(signing_priv_key != NULL) // private key to serialize { for(counter=2*SGX_ECP256_KEY_SIZE;counter<3*SGX_ECP256_KEY_SIZE; counter++) *(private_public_key_string+counter)=signing_priv_key->r[counter - 2*SGX_ECP256_KEY_SIZE]; } } } // todo: set to private void deserialize_string_to_key_pair(uint8_t* private_public_key_string, sgx_ec256_public_t* pub_key, sgx_ec256_private_t* signing_priv_key) { if(private_public_key_string != NULL) // nowhere to deserialize from { uint32_t counter; if(signing_priv_key != NULL) { for(counter=2*SGX_ECP256_KEY_SIZE;counter<3*SGX_ECP256_KEY_SIZE; counter++) signing_priv_key->r[counter-2*SGX_ECP256_KEY_SIZE]=*(private_public_key_string+counter); } if(pub_key != NULL) { for(counter=0;countergx[counter]=*(private_public_key_string+counter); for(counter=SGX_ECP256_KEY_SIZE;counter<2*SGX_ECP256_KEY_SIZE; counter++) pub_key->gy[counter-SGX_ECP256_KEY_SIZE]=*(private_public_key_string+counter); } } } uint32_t create_and_seal_ecdsa_signing_key_pair(__attribute__((unused)) sgx_ec256_public_t* pub_key, __attribute__((unused)) uint32_t* sealed_data_length, __attribute__((unused)) uint8_t* sealed_data) { uint32_t ret_status; sgx_ec256_private_t private_key; uint32_t counter; ret_status=create_ec_key_pair(pub_key, &private_key); if(ret_status!=SGX_SUCCESS) return ret_status; for(counter=0;counter