/* * 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.challa * */ // App.cpp : Defines the entry point for the console application. #include #include #include "../Decryptor/Decryptor_u.h" #include "sgx_eid.h" #include "sgx_urts.h" #define __STDC_FORMAT_MACROS #include #include // for sealing - sgx_calc_sealed_data_size #include "sgx_tseal.h" #include "LocalAttestationUntrusted.h" // For reading from/writing to file -sealing. #include #include #include #include //#define UNUSED(val) (void)(val) #define TCHAR char #define _TCHAR char #define _T(str) str #define scanf_s scanf // Not sure if I need this later - as such, I (decryptor app) will only ever need to talk to 1 enclave at a time - verifier enclave first and then the apache enclave. //extern std::mapg_enclave_id_map; //int __ImageBase=0; sgx_enclave_id_t e2_enclave_id = 0; #define Decryptor_PATH "libDecryptor.so" ////////////////////////////////////////////////// #include uint32_t write_to_fd(int fd, uint8_t* msg, uint32_t* expected_msg_length) { lseek(fd, 0, SEEK_SET); ssize_t bytes_written; bytes_written = write(fd, msg, *expected_msg_length); if(bytes_written <= 0) return 0xFFFFFFFF; fsync(fd); *expected_msg_length = bytes_written; return 0; } uint32_t read_from_fd(int fd, uint8_t* msg, uint32_t* expected_msg_length) { ssize_t bytes_read; lseek(fd, 0, SEEK_SET); bytes_read = read(fd, msg, *expected_msg_length); if(bytes_read <= 0) return 0xFFFFFFFF; *expected_msg_length = bytes_read; return 0; } uint32_t unseal_signing_key_pair_from_disk(int fd, size_t sealed_msg_length_in_file) { uint32_t ret_status=0, length=sealed_msg_length_in_file, counter=0; uint8_t* sealed_data; sealed_data = (uint8_t*) malloc(0x300); //TODO: Get length of the sealed msg and try to read that much from the file. // May be pass the length of the file as input to this function and check that it is at least as much as the output of the sgx call. ret_status = read_from_fd(fd, sealed_data, &length); if(ret_status != 0) { free(sealed_data); return 0xFFFFFFFF; } for(counter=0;counter