Skip to content

Commit

Permalink
Merge pull request intel#568 from GuilhemN/master
Browse files Browse the repository at this point in the history
Fix some more typos
  • Loading branch information
llly committed Jul 20, 2020
2 parents d1029a5 + 746e602 commit 7c2e2f9
Show file tree
Hide file tree
Showing 25 changed files with 113 additions and 124 deletions.
Expand Up @@ -45,9 +45,9 @@

extern sgx_enclave_id_t responder_enclave_id;

/* Function Description: This is OCALL interface for initiator enclave to get ECDH message 1 and session id from responder enclave
/* Function Description: This is OCALL interface for initiator enclave to get ECDH message 1 and session id from responder enclave
* Parameter Description:
* [input, output] dh_msg1: pointer to ecdh msg1 buffer, this buffer is alloated in initiator enclave and filled by reponser enclave
* [input, output] dh_msg1: pointer to ecdh msg1 buffer, this buffer is allocated in initiator enclave and filled by responder enclave
* [output] session_id: pointer to session id which is allocated by responder enclave
* */
extern "C" ATTESTATION_STATUS session_request_ocall(sgx_dh_msg1_t* dh_msg1, uint32_t* session_id)
Expand All @@ -65,7 +65,7 @@ extern "C" ATTESTATION_STATUS session_request_ocall(sgx_dh_msg1_t* dh_msg1, uint
/* Function Description: This is OCALL interface for initiator enclave to send ECDH message 2 to responder enclave, and receive ECDH message 3 from responder enclave
* Parameter Description:
* [input] dh_msg2: this is pointer to ECDH message 2 generated by initiator enclave
* [input, output]dh_msg3: this is pointer to ECDH message 3, this buffer is allocated in initiator enclave and filled by respoonder enclave
* [input, output]dh_msg3: this is pointer to ECDH message 3, this buffer is allocated in initiator enclave and filled by responder enclave
* [input] session_id: this is session id allocated by responder enclave
* */
ATTESTATION_STATUS exchange_report_ocall(sgx_dh_msg2_t *dh_msg2, sgx_dh_msg3_t *dh_msg3, uint32_t session_id)
Expand All @@ -85,7 +85,7 @@ ATTESTATION_STATUS exchange_report_ocall(sgx_dh_msg2_t *dh_msg2, sgx_dh_msg3_t *
* [input] session_id: this is session id allocated by responder enclave
* [input] req_message: this is pointer to request message
* [input] req_message_size: this is request message size
* [input] max_payload_size: this is maxium payload size in response message
* [input] max_payload_size: this is maximum payload size in response message
* [input, output] this is pointer to response message, the buffer is allocated by initiator enclave and filled by responder enclave
* [input] response message size
* */
Expand All @@ -97,11 +97,11 @@ ATTESTATION_STATUS send_request_ocall(uint32_t session_id, secure_message_t* req
ret = generate_response(responder_enclave_id, &retcode, req_message, req_message_size, max_payload_size, resp_message, resp_message_size, session_id);
if (ret != SGX_SUCCESS || retcode != SGX_SUCCESS)
return INVALID_SESSION;

return (ATTESTATION_STATUS)0;
}

/* Function Description: this is OCALL interface for initiator enclave to close secure session
/* Function Description: this is OCALL interface for initiator enclave to close secure session
* Parameter Description:
* [input] session_id: this is session id allocated by responder enclave
* */
Expand Down
Expand Up @@ -46,17 +46,17 @@
extern "C" {
#endif

/* Function Description: This is OCALL interface for initiator enclave to get ECDH message 1 and session id from responder enclave
/* Function Description: This is OCALL interface for initiator enclave to get ECDH message 1 and session id from responder enclave
* Parameter Description:
* [input, output] dh_msg1: pointer to ecdh msg1 buffer, this buffer is alloated in initiator enclave and filled by reponser enclave
* [input, output] dh_msg1: pointer to ecdh msg1 buffer, this buffer is allocated in initiator enclave and filled by reponsder enclave
* [output] session_id: pointer to session id which is allocated by responder enclave
* */
uint32_t session_request_ocall(sgx_dh_msg1_t* dh_msg1, uint32_t* session_id);

/* Function Description: This is OCALL interface for initiator enclave to send ECDH message 2 to responder enclave, and receive ECDH message 3 from responder enclave
* Parameter Description:
* [input] dh_msg2: this is pointer to ECDH message 2 generated by initiator enclave
* [input, output]dh_msg3: this is pointer to ECDH message 3, this buffer is allocated in initiator enclave and filled by respoonder enclave
* [input, output]dh_msg3: this is pointer to ECDH message 3, this buffer is allocated in initiator enclave and filled by responder enclave
* [input] session_id: this is session id allocated by responder enclave
* */
uint32_t exchange_report_ocall(sgx_dh_msg2_t* dh_msg2, sgx_dh_msg3_t* dh_msg3, uint32_t session_id);
Expand All @@ -66,14 +66,14 @@ uint32_t exchange_report_ocall(sgx_dh_msg2_t* dh_msg2, sgx_dh_msg3_t* dh_msg3, u
* [input] session_id: this is session id allocated by responder enclave
* [input] req_message: this is pointer to request message
* [input] req_message_size: this is request message size
* [input] max_payload_size: this is maxium payload size in response message
* [input] max_payload_size: this is maximum payload size in response message
* [input, output] this is pointer to response message, the buffer is allocated by initiator enclave and filled by responder enclave
* [input] response message size
* */
uint32_t send_request_ocall(uint32_t session_id, secure_message_t* req_message, size_t req_message_size, size_t max_payload_size, secure_message_t* resp_message, size_t resp_message_size);


/* Function Description: this is OCALL interface for initiator enclave to close secure session
/* Function Description: this is OCALL interface for initiator enclave to close secure session
* Parameter Description:
* [input] session_id: this is session id allocated by responder enclave
* */
Expand Down
Expand Up @@ -46,7 +46,7 @@

/* Function Description: This is OCALL interface for initiator enclave to get ECDH message 1 and session id from responder enclave
* Parameter Description:
* [input, output] dh_msg1: pointer to ecdh msg1 buffer, this buffer is alloated in initiator enclave and filled by reponser enclave
* [input, output] dh_msg1: pointer to ecdh msg1 buffer, this buffer is allocated in initiator enclave and filled by responder enclave
* [output] session_id: pointer to session id which is allocated by responder enclave
* */
extern "C" ATTESTATION_STATUS session_request_ocall(sgx_dh_msg1_t* dh_msg1, uint32_t* session_id)
Expand All @@ -58,7 +58,7 @@ extern "C" ATTESTATION_STATUS session_request_ocall(sgx_dh_msg1_t* dh_msg1, uint

msg1_request.header.type = FIFO_DH_REQ_MSG1;
msg1_request.header.size = 0;

if ((client_send_receive(&msg1_request, sizeof(FIFO_MSG), &msg1_response, &msg1_resp_size) != 0)
|| (msg1_response == NULL))
{
Expand All @@ -78,7 +78,7 @@ extern "C" ATTESTATION_STATUS session_request_ocall(sgx_dh_msg1_t* dh_msg1, uint
/* Function Description: This is OCALL interface for initiator enclave to send ECDH message 2 to responder enclave, and receive ECDH message 3 from responder enclave
* Parameter Description:
* [input] dh_msg2: this is pointer to ECDH message 2 generated by initiator enclave
* [input, output]dh_msg3: this is pointer to ECDH message 3, this buffer is allocated in initiator enclave and filled by respoonder enclave
* [input, output]dh_msg3: this is pointer to ECDH message 3, this buffer is allocated in initiator enclave and filled by responder enclave
* [input] session_id: this is session id allocated by responder enclave
* */
ATTESTATION_STATUS exchange_report_ocall(sgx_dh_msg2_t *dh_msg2, sgx_dh_msg3_t *dh_msg3, uint32_t session_id)
Expand All @@ -95,13 +95,13 @@ ATTESTATION_STATUS exchange_report_ocall(sgx_dh_msg2_t *dh_msg2, sgx_dh_msg3_t *
{
return ERROR_OUT_OF_MEMORY;
}
memset(msg2, 0, msg2size);
memset(msg2, 0, msg2size);

msg2_header = (FIFO_MSG_HEADER *)msg2;
msg2_header->type = FIFO_DH_MSG2;
msg2_header->size = sizeof(SESSION_MSG2);

msg2_body = (SESSION_MSG2 *)msg2->msgbuf;
msg2_body = (SESSION_MSG2 *)msg2->msgbuf;
memcpy(&msg2_body->dh_msg2, dh_msg2, sizeof(sgx_dh_msg2_t));
msg2_body->sessionid = session_id;

Expand All @@ -117,7 +117,7 @@ ATTESTATION_STATUS exchange_report_ocall(sgx_dh_msg2_t *dh_msg2, sgx_dh_msg3_t *

free(msg3);
free(msg2);

return (ATTESTATION_STATUS)0;
}

Expand All @@ -126,15 +126,15 @@ ATTESTATION_STATUS exchange_report_ocall(sgx_dh_msg2_t *dh_msg2, sgx_dh_msg3_t *
* [input] session_id: this is session id allocated by responder enclave
* [input] req_message: this is pointer to request message
* [input] req_message_size: this is request message size
* [input] max_payload_size: this is maxium payload size in response message
* [input] max_payload_size: this is maximum payload size in response message
* [input, output] this is pointer to response message, the buffer is allocated by initiator enclave and filled by responder enclave
* [input] response message size
* */
ATTESTATION_STATUS send_request_ocall(uint32_t session_id, secure_message_t* req_message, size_t req_message_size, size_t max_payload_size, secure_message_t* resp_message, size_t resp_message_size)
{
FIFO_MSG *msgreq = NULL, * msgresp= NULL;
FIFO_MSGBODY_REQ * msgbody;

size_t reqsize, respsize;

reqsize = sizeof(FIFO_MSG_HEADER) + sizeof(FIFO_MSGBODY_REQ) + req_message_size;
Expand Down Expand Up @@ -189,7 +189,7 @@ ATTESTATION_STATUS end_session_ocall(uint32_t session_id)
{
return ERROR_OUT_OF_MEMORY;
}
memset(closemsg, 0,reqsize);
memset(closemsg, 0,reqsize);

closemsg->header.type = FIFO_DH_CLOSE_REQ;
closemsg->header.size = sizeof(SESSION_CLOSE_REQ);
Expand Down
Expand Up @@ -48,15 +48,15 @@ extern "C" {

/* Function Description: This is OCALL interface for initiator enclave to get ECDH message 1 and session id from responder enclave
* Parameter Description:
* [input, output] dh_msg1: pointer to ecdh msg1 buffer, this buffer is alloated in initiator enclave and filled by reponser enclave
* [input, output] dh_msg1: pointer to ecdh msg1 buffer, this buffer is allocated in initiator enclave and filled by responder enclave
* [output] session_id: pointer to session id which is allocated by responder enclave
* */
uint32_t session_request_ocall(sgx_dh_msg1_t* dh_msg1, uint32_t* session_id);

/* Function Description: This is OCALL interface for initiator enclave to send ECDH message 2 to responder enclave, and receive ECDH message 3 from responder enclave
* Parameter Description:
* [input] dh_msg2: this is pointer to ECDH message 2 generated by initiator enclave
* [input, output]dh_msg3: this is pointer to ECDH message 3, this buffer is allocated in initiator enclave and filled by respoonder enclave
* [input, output]dh_msg3: this is pointer to ECDH message 3, this buffer is allocated in initiator enclave and filled by responder enclave
* [input] session_id: this is session id allocated by responder enclave
* */
uint32_t exchange_report_ocall(sgx_dh_msg2_t* dh_msg2, sgx_dh_msg3_t* dh_msg3, uint32_t session_id);
Expand All @@ -66,7 +66,7 @@ uint32_t exchange_report_ocall(sgx_dh_msg2_t* dh_msg2, sgx_dh_msg3_t* dh_msg3, u
* [input] session_id: this is session id allocated by responder enclave
* [input] req_message: this is pointer to request message
* [input] req_message_size: this is request message size
* [input] max_payload_size: this is maxium payload size in response message
* [input] max_payload_size: this is maximum payload size in response message
* [input, output] this is pointer to response message, the buffer is allocated by initiator enclave and filled by responder enclave
* [input] response message size
* */
Expand Down
4 changes: 2 additions & 2 deletions SampleCode/LocalAttestation/AppInitiator/datatypes.h
Expand Up @@ -75,8 +75,8 @@ typedef uint8_t cmac_128[MAC_SIZE];
//Format of the AES-GCM message being exchanged between the source and the destination enclaves
typedef struct _secure_message_t
{
uint32_t session_id; //Session ID identifyting the session to which the message belongs
sgx_aes_gcm_data_t message_aes_gcm_data;
uint32_t session_id; //Session ID identifying the session to which the message belongs
sgx_aes_gcm_data_t message_aes_gcm_data;
}secure_message_t;

//Format of the input function parameter structure
Expand Down
4 changes: 2 additions & 2 deletions SampleCode/LocalAttestation/AppResponder/App.cpp
Expand Up @@ -77,7 +77,7 @@ void signal_handler(int sig)
default:
break;
}

exit(1);
}

Expand All @@ -93,7 +93,7 @@ int main(int argc, char* argv[])
if (!g_cptask || !g_cpserver)
return -1;

// registger signal handler so to respond to user interception
// register signal handler so to respond to user interception
signal(SIGINT, signal_handler);
signal(SIGTERM, signal_handler);

Expand Down
52 changes: 26 additions & 26 deletions SampleCode/LocalAttestation/AppResponder/CPServer.cpp
Expand Up @@ -41,8 +41,8 @@

#include "CPServer.h"

#define BACKLOG 5
#define CONCURRENT_MAX 32
#define BACKLOG 5
#define CONCURRENT_MAX 32
#define SERVER_PORT 8888
#define BUFFER_SIZE 1024

Expand All @@ -51,12 +51,12 @@
/* Function Description:
* This is server initialization routine, it creates TCP sockets and listen on a port.
* In Linux, it would listen on domain socket named '/tmp/UNIX.domain'
* In Windows, it would listen on port 8888, which is for demonstration purpose
* In Windows, it would listen on port 8888, which is for demonstration purpose
* */
int CPServer::init()
{
struct sockaddr_un srv_addr;

m_server_sock_fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (m_server_sock_fd == -1)
{
Expand All @@ -75,7 +75,7 @@ int CPServer::init()
close(m_server_sock_fd);
return -1;
}

if (listen(m_server_sock_fd, BACKLOG) == -1)
{
printf("listen error\n");
Expand All @@ -97,26 +97,26 @@ void CPServer::doWork()
int client_fds[CONCURRENT_MAX] = {0};
fd_set server_fd_set;
int max_fd = -1;
struct timeval tv;
struct timeval tv;
char input_msg[BUFFER_SIZE];
char recv_msg[BUFFER_SIZE];

while (!m_shutdown)
{
// set 20s timeout for select()
// set 20s timeout for select()
tv.tv_sec = 20;
tv.tv_usec = 0;
FD_ZERO(&server_fd_set);

FD_SET(STDIN_FILENO, &server_fd_set);
if (max_fd <STDIN_FILENO)
max_fd = STDIN_FILENO;

// listening on server socket
FD_SET(m_server_sock_fd, &server_fd_set);
if (max_fd < m_server_sock_fd)
max_fd = m_server_sock_fd;

// listening on all client connections
for(int i =0; i < CONCURRENT_MAX; i++) {
if(client_fds[i] != 0) {
Expand All @@ -125,24 +125,24 @@ void CPServer::doWork()
max_fd = client_fds[i];
}
}

int ret = select(max_fd + 1, &server_fd_set, NULL, NULL, &tv);
if(ret < 0) {
printf("Warning: server would shutdown\n");
continue;
} else if(ret == 0) {
// timeout
// timeout
continue;
}
}

if(FD_ISSET(m_server_sock_fd, &server_fd_set)) {
// if there is new connection request
struct sockaddr_un clt_addr;
socklen_t len = sizeof(clt_addr);

// accept this connection request
int client_sock_fd = accept(m_server_sock_fd, (struct sockaddr *)&clt_addr, &len);

if (client_sock_fd > 0) {
// add new connection to connection pool if it's not full
int index = -1;
Expand All @@ -153,7 +153,7 @@ void CPServer::doWork()
break;
}
}

if(index < 0) {
printf("server reach maximum connection!\n");
bzero(input_msg, BUFFER_SIZE);
Expand All @@ -166,20 +166,20 @@ void CPServer::doWork()
break;
}
}

for(int i =0; i < CONCURRENT_MAX; i++) {
if ((client_fds[i] !=0)
&& (FD_ISSET(client_fds[i], &server_fd_set)))
&& (FD_ISSET(client_fds[i], &server_fd_set)))
{
// there is request messages from client connectsions
FIFO_MSG * msg;
// there is request messages from client connections
FIFO_MSG * msg;

bzero(recv_msg, BUFFER_SIZE);
long byte_num = recv(client_fds[i], recv_msg, BUFFER_SIZE, 0);
if (byte_num > 0) {
if(byte_num > BUFFER_SIZE)
byte_num = BUFFER_SIZE;
byte_num = BUFFER_SIZE;

recv_msg[byte_num] = '\0';

msg = (FIFO_MSG *)malloc(byte_num);
Expand All @@ -188,11 +188,11 @@ void CPServer::doWork()
continue;
}
memset(msg, 0, byte_num);

memcpy(msg, recv_msg, byte_num);

msg->header.sockfd = client_fds[i];

// put request message to event queue
m_cptask->puttask(msg);
}
Expand All @@ -217,6 +217,6 @@ void CPServer::shutDown()
printf("Server would shutdown...\n");
m_shutdown = 1;
m_cptask->shutdown();

close(m_server_sock_fd);
}

0 comments on commit 7c2e2f9

Please sign in to comment.