// App.cpp : Defines the entry point for the console application. #include #include #include "sgx_eid.h" #include "sgx_urts.h" #define __STDC_FORMAT_MACROS #include // #include "LocalAttestationUntrusted.h" #include "Sealing.h" #include "MainLogic.h" //#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 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