// // Created by miti on 2019-12-21. // #include "../Include/Sealing.h" uint32_t Sealing::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; close(fd); return 0; } uint32_t Sealing::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 Sealing::unseal_signing_key_pair_from_disk(sgx_enclave_id_t enclave_id, 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