/* * 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 "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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; uint8_t Decryptor::apache_mr_signer[32] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; 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; } uint32_t Decryptor::create_mitigator_header_H(uint8_t* signature_data, uint8_t* signature) { uint32_t internal_return_status; uint8_t local_signature[64]; uint8_t local_signature_data[ECDH_PUBLIC_KEY_SIZE + 32]; uint32_t counter; // Otherwise: DoS or possible bypass (fake verifier does LA but real verifier mrenclave is given out by decryptor) - signature with junk verifier mrenclave or whatever is in the memory. if(LocalAttestationTrusted::get_one_successful_la_done() < 1) return 0xde; // This needs to be called at any point after the first local attestation is done - else, a junk verifier mrenclave will be included in the signature internal_return_status = Decryptor::create_mitigator_token_M(local_signature_data); if(internal_return_status != 0x0) return internal_return_status; internal_return_status = signatureBox.sign(local_signature_data, ECDH_PUBLIC_KEY_SIZE + 32, local_signature); if(internal_return_status != 0x0) return internal_return_status; for(counter=0;counter