[Assignment-7] app restructure and cleanup
This commit is contained in:
parent
9cd7ef8703
commit
feb0bd1b73
10 changed files with 304 additions and 345 deletions
|
|
@ -1,11 +1,16 @@
|
|||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "employee.h"
|
||||
#include "util.h"
|
||||
#include "proxy.h"
|
||||
#include "proxysetup.h"
|
||||
#include "intermediary.h"
|
||||
|
||||
|
||||
static char* BIN_NAME = "SignatureProxy";
|
||||
|
|
@ -24,8 +29,8 @@ void syntax_exit(void) {
|
|||
"\n"
|
||||
"%s";
|
||||
|
||||
printf(syntax, BIN_NAME, intermediary_syntax(), proxy_syntax(), proxysetup_syntax());
|
||||
exit(1);
|
||||
printf(syntax, BIN_NAME, employee_syntax(), proxy_syntax(), proxysetup_syntax());
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
void set_bin_name(char* bin_name) {
|
||||
|
|
@ -118,7 +123,7 @@ static sgx_errlist_t sgx_errlist[] = {
|
|||
};
|
||||
|
||||
/* Check error conditions for loading enclave */
|
||||
void print_error_message(sgx_status_t ret)
|
||||
void sgx_print_error_message(sgx_status_t ret)
|
||||
{
|
||||
size_t idx = 0;
|
||||
size_t ttl = sizeof sgx_errlist/sizeof sgx_errlist[0];
|
||||
|
|
@ -161,7 +166,7 @@ int initialize_enclave(char* token_path) {
|
|||
|
||||
ret = sgx_create_enclave("enclave.signed.so", SGX_DEBUG_FLAG, &token, &updated, &global_eid, NULL);
|
||||
if (ret != SGX_SUCCESS) {
|
||||
print_error_message(ret);
|
||||
sgx_print_error_message(ret);
|
||||
return (1);
|
||||
}
|
||||
|
||||
|
|
@ -183,3 +188,43 @@ int initialize_enclave(char* token_path) {
|
|||
sgx_enclave_id_t get_global_eid(void){
|
||||
return global_eid;
|
||||
}
|
||||
|
||||
int load_file(const char* path, uint8_t** data, size_t* data_len) {
|
||||
FILE* file;
|
||||
size_t file_size;
|
||||
uint8_t* buf;
|
||||
|
||||
int file_des = open(path, O_RDWR);
|
||||
if(file_des == 0)
|
||||
return (1);
|
||||
|
||||
struct stat stat;
|
||||
if (fstat(file_des, &stat) != 0){
|
||||
close(file_des);
|
||||
return (2);
|
||||
}
|
||||
|
||||
close(file_des);
|
||||
|
||||
file_size = stat.st_size;
|
||||
buf = malloc(file_size);
|
||||
if (buf == NULL)
|
||||
return (3);
|
||||
|
||||
file = fopen(path, "rb");
|
||||
if(file == NULL){
|
||||
free(buf);
|
||||
return (4);
|
||||
}
|
||||
|
||||
if (fread(buf, file_size, 1, file) != 1 || ferror(file) != 0) {
|
||||
free(buf);
|
||||
fclose(file);
|
||||
return (5);
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
*data = buf;
|
||||
*data_len = file_size;
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue