/* * 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. * */ // question 1: When should I call the create_mitigator_header_H function? It can be called as early as verify_peer_enclave_trust. Or as late as when encrypt_mitigator_header_H_to_apache is called. But then you need to make sure that successful_la_count is right for that. // question 2: nightmare about the process_message_generate_response function. #include "Decryptor.h" #include "sgx_tseal.h" #include "sgx_tcrypto.h" #include "sgx_dh.h" #include "datatypes.h" #include "error_codes.h" ECDSASignatureBox Decryptor::signatureBox; HybridEncryptionBox Decryptor::hybridEncryptionBoxClient; SymmetricEncryptionBox Decryptor::symmetricEncryptionBoxApache; SymmetricEncryptionBox Decryptor::symmetricEncryptionBoxVerifier; uint8_t Decryptor::verifier_mr_enclave[32] = {0}; uint8_t Decryptor::apache_mr_signer[32] = {0}; unsigned int successful_la_count; uint8_t Decryptor::plaintext_mitigator_header_H[ECDH_PUBLIC_KEY_SIZE + 32 + 64]={0}; // INTERNAL uint32_t Decryptor::create_mitigator_token_M(uint8_t* token) { uint32_t internal_return_status; uint32_t counter; // create short-term ECDH key pair internal_return_status = hybridEncryptionBoxClient.generate_keypair(); if(internal_return_status == NULL) return 0xff; hybridEncryptionBoxClient.get_public_key(token); // create token: concatenate short-term keypair with verifiers mrenclave. for(counter=0;counter<32;counter++) *(token + counter + ECDH_PUBLIC_KEY_SIZE) = verifier_mr_enclave[counter]; return 0; } // INTERNAL uint32_t Decryptor::create_mitigator_header_H(uint8_t* signature_data_and_signature) { uint32_t internal_return_status; uint8_t local_signature_data_and_signature[ECDH_PUBLIC_KEY_SIZE + 32 + 64]; uint32_t counter; internal_return_status = Decryptor::create_mitigator_token_M(local_signature_data_and_signature); if(internal_return_status != 0x0) return internal_return_status; internal_return_status = signatureBox.sign(local_signature_data_and_signature, ECDH_PUBLIC_KEY_SIZE + 32, local_signature_and_signature + ECDH_PUBLIC_KEY_SIZE + 32); if(internal_return_status != 0x0) return internal_return_status; for(counter=0;counter