Finished changing the files in /psk to more closely follow the coding standard.

pull/50/head
Conner 2017-05-16 16:29:22 -06:00
parent 8bfdd52d09
commit 200708b5f5
5 changed files with 133 additions and 115 deletions

View File

@ -60,14 +60,17 @@ static inline int tcp_select(int socketfd, int to_sec)
result = select(nfds, &recvfds, NULL, &errfds, &timeout);
if (result == 0)
if (result == 0) {
return TEST_TIMEOUT;
}
else if (result > 0) {
if (FD_ISSET(socketfd, &recvfds))
if (FD_ISSET(socketfd, &recvfds)) {
return TEST_RECV_READY;
else if(FD_ISSET(socketfd, &errfds))
}
else if(FD_ISSET(socketfd, &errfds)) {
return TEST_ERROR_READY;
}
}
return TEST_SELECT_FAIL;
}
@ -87,10 +90,12 @@ static int NonBlockingSSL_Connect(WOLFSSL* ssl)
error == SSL_ERROR_WANT_WRITE)) {
currTimeout = 1;
if (error == SSL_ERROR_WANT_READ)
if (error == SSL_ERROR_WANT_READ) {
printf("... client would read block\n");
else
}
else {
printf("... client would write block\n");
}
select_ret = tcp_select(sockfd, currTimeout);

View File

@ -194,8 +194,9 @@ int main(int argc, char **argv){
}
/* check to see if the session id is being reused */
if (wolfSSL_session_reused(sslResume))
if (wolfSSL_session_reused(sslResume)) {
printf("reused session id\n");
}
else
printf("didn't reuse session id!!!\n");

View File

@ -144,13 +144,13 @@ int main(int argc, char **argv)
/* associate the file descriptor with the session */
ret = wolfSSL_set_fd(ssl, sockfd);
if (ret != SSL_SUCCESS){
if (ret != SSL_SUCCESS) {
return 1;
}
/* takes inputting string and outputs it to the server */
ret = SendReceive(ssl);
if(ret != 0){
if (ret != 0) {
return 1;
}

View File

@ -68,14 +68,17 @@ int tcp_select(int sockfd, int to_sec)
result = select(nfds, &recvfds, NULL, &errfds, &timeout);
/* logic for which enumerated value is returned */
if (result == 0)
if (result == 0) {
return TEST_TIMEOUT;
}
else if (result > 0) {
if (FD_ISSET(sockfd, &recvfds))
if (FD_ISSET(sockfd, &recvfds)) {
return TEST_RECV_READY;
else if (FD_ISSET(sockfd, &errfds))
}
else if (FD_ISSET(sockfd, &errfds)) {
return TEST_ERROR_READY;
}
}
return TEST_SELECT_FAIL;
}
@ -99,10 +102,12 @@ int NonBlockingSSL(WOLFSSL* ssl)
int currTimeout = 1;
/* print out for user notification */
if (error == SSL_ERROR_WANT_READ)
if (error == SSL_ERROR_WANT_READ) {
printf("... server would read block\n");
else
}
else {
printf("... server would write block\n");
}
select_ret = tcp_select(sockfd, currTimeout);
@ -132,7 +137,7 @@ int NonBlockingSSL(WOLFSSL* ssl)
/*
* Handles response to client.
*/
int respond(WOLFSSL* ssl)
int Respond(WOLFSSL* ssl)
{
int n; /* length of string read */
char buf[MAXLINE]; /* string read from client */
@ -140,8 +145,10 @@ int respond(WOLFSSL* ssl)
memset(buf, 0, MAXLINE);
do {
if (NonBlockingSSL(ssl) != SSL_SUCCESS)
if (NonBlockingSSL(ssl) != SSL_SUCCESS) {
return 1;
}
n = wolfSSL_read(ssl, buf, MAXLINE);
if (n > 0) {
printf("%s\n", buf);
@ -149,8 +156,10 @@ int respond(WOLFSSL* ssl)
}
while(n < 0);
if (NonBlockingSSL(ssl) != SSL_SUCCESS)
if (NonBlockingSSL(ssl) != SSL_SUCCESS) {
return 1;
}
if (wolfSSL_write(ssl, response, strlen(response)) != strlen(response)) {
printf("Fatal error : respond: write error\n");
return 1;
@ -168,8 +177,9 @@ static inline unsigned int my_psk_server_cb(WOLFSSL* ssl, const char* identity,
(void)ssl;
(void)key_max_len;
if (strncmp(identity, "Client_identity", 15) != 0)
if (strncmp(identity, "Client_identity", 15) != 0) {
return 0;
}
key[0] = 26;
key[1] = 43;
@ -200,8 +210,9 @@ int main()
wolfSSL_CTX_set_psk_server_callback(ctx, my_psk_server_cb);
wolfSSL_CTX_use_psk_identity_hint(ctx, "wolfssl server");
if (wolfSSL_CTX_set_cipher_list(ctx, "PSK-AES128-CBC-SHA256")
!= SSL_SUCCESS)
!= SSL_SUCCESS) {
printf("Fatal error : server can't set cipher list\n");
}
/* find a socket */
listenfd = socket(AF_INET, SOCK_STREAM, 0);
@ -264,9 +275,10 @@ int main()
printf("Fatal error : fcntl set failed\n");
return 1;
}
if (respond(ssl) != 0)
if (Respond(ssl) != 0) {
printf("Fatal error : respond error\n");
return 1;
}
/* closes the connections after responding */
wolfSSL_shutdown(ssl);