From 8bfdd52d09b5b5ae4aad0910b3a67dfc7ef4eaef Mon Sep 17 00:00:00 2001 From: Conner Date: Tue, 16 May 2017 15:40:10 -0600 Subject: [PATCH] Changed server-psk.c to more closely follow the coding standard. --- psk/server-psk.c | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/psk/server-psk.c b/psk/server-psk.c index 5b89a22a..c941b349 100644 --- a/psk/server-psk.c +++ b/psk/server-psk.c @@ -1,6 +1,6 @@ /* server-psk.c - * A server ecample using a TCP connection with PSK security. - * + * A server ecample using a TCP connection with PSK security. + * * Copyright (C) 2006-2015 wolfSSL Inc. * * This file is part of wolfSSL. (formerly known as CyaSSL) @@ -36,10 +36,10 @@ #define LISTENQ 1024 #define SERV_PORT 11111 -/* +/* * 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 */ @@ -64,14 +64,15 @@ int respond(WOLFSSL* ssl) /* * Identify which psk key to use. */ -static unsigned int my_psk_server_cb(WOLFSSL* ssl, const char* identity, unsigned char* key, - unsigned int key_max_len) +static unsigned int my_psk_server_cb(WOLFSSL* ssl, const char* identity, + unsigned char* key, unsigned int key_max_len) { (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; @@ -91,14 +92,14 @@ int main() WOLFSSL_CTX* ctx; wolfSSL_Init(); - + /* create ctx and configure certificates */ if ((ctx = wolfSSL_CTX_new(wolfSSLv23_server_method())) == NULL) { printf("Fatal error : wolfSSL_CTX_new error\n"); return 1; } - - /* use psk suite for security */ + + /* use psk suite for security */ 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") @@ -114,7 +115,7 @@ int main() servAddr.sin_addr.s_addr = htonl(INADDR_ANY); servAddr.sin_port = htons(SERV_PORT); - /* find a socket */ + /* find a socket */ listenfd = socket(AF_INET, SOCK_STREAM, 0); if (listenfd < 0) { printf("Fatal error : socket error\n"); @@ -132,17 +133,17 @@ int main() printf("Fatal error : bind error\n"); return 1; } - - /* listen to the socket */ + + /* listen to the socket */ if (listen(listenfd, LISTENQ) < 0) { printf("Fatal error : listen error\n"); return 1; } - + /* main loop for accepting and responding to clients */ for ( ; ; ) { WOLFSSL* ssl; - + cliLen = sizeof(cliAddr); connfd = accept(listenfd, (struct sockaddr *) &cliAddr, &cliLen); if (connfd < 0) { @@ -153,20 +154,21 @@ int main() printf("Connection from %s, port %d\n", inet_ntop(AF_INET, &cliAddr.sin_addr, buff, sizeof(buff)), ntohs(cliAddr.sin_port)); - + /* create WOLFSSL object and respond */ if ((ssl = wolfSSL_new(ctx)) == NULL) { printf("Fatal error : wolfSSL_new error\n"); return 1; } wolfSSL_set_fd(ssl, connfd); - if (respond(ssl) != 0) + if (Respond(ssl) != 0) { return 1; - + } + /* closes the connections after responding */ wolfSSL_shutdown(ssl); wolfSSL_free(ssl); - + if (close(connfd) == -1) { printf("Fatal error : close error\n"); return 1;