From 58dce0062b152258367e3159bd0dc1d786622b88 Mon Sep 17 00:00:00 2001 From: Levi Rak Date: Fri, 2 Jun 2017 09:56:23 -0600 Subject: [PATCH] touch-up --- tls/client-tcp.c | 4 ++-- tls/client-tls-callback.c | 10 ++++++---- tls/client-tls-ecdhe.c | 3 ++- tls/client-tls-nonblocking.c | 6 ++---- tls/client-tls-perf.c | 0 tls/client-tls-resume.c | 10 +++++++--- tls/client-tls-writedup.c | 14 +++++++------- tls/client-tls.c | 4 ++-- tls/server-tcp.c | 7 ++++++- tls/server-tls-callback.c | 22 ++++++++++------------ tls/server-tls-ecdhe.c | 8 +++++--- tls/server-tls-epoll-perf.c | 0 tls/server-tls-epoll-threaded.c | 0 tls/server-tls-nonblocking.c | 15 +++++---------- tls/server-tls-threaded.c | 24 ++++++++---------------- tls/server-tls.c | 15 +++++---------- 16 files changed, 67 insertions(+), 75 deletions(-) mode change 100755 => 100644 tls/client-tls-perf.c mode change 100755 => 100644 tls/server-tls-epoll-perf.c mode change 100755 => 100644 tls/server-tls-epoll-threaded.c diff --git a/tls/client-tcp.c b/tls/client-tcp.c index 70828366..4d1504db 100644 --- a/tls/client-tcp.c +++ b/tls/client-tcp.c @@ -30,10 +30,10 @@ #include #include - - #define DEFAULT_PORT 11111 + + int main(int argc, char** argv) { int sockfd; diff --git a/tls/client-tls-callback.c b/tls/client-tls-callback.c index cb9b97fe..ca554789 100644 --- a/tls/client-tls-callback.c +++ b/tls/client-tls-callback.c @@ -34,6 +34,10 @@ /* wolfSSL */ #include +#define DEFAULT_PORT 11111 + +#define CERT_FILE "../certs/ca-cert.pem" + int my_IORecv(WOLFSSL* ssl, char* buff, int sz, void* ctx) { @@ -134,9 +138,6 @@ int my_IOSend(WOLFSSL* ssl, char* buff, int sz, void* ctx) } -#define DEFAULT_PORT 11111 - -#define CERT_FILE "../certs/ca-cert.pem" int main(int argc, char** argv) { @@ -210,7 +211,8 @@ int main(int argc, char** argv) /* Connect to the server */ - if (connect(sockfd, (struct sockaddr*) &servAddr, sizeof(servAddr)) < 0) { + if (connect(sockfd, (struct sockaddr*) &servAddr, sizeof(servAddr)) + == -1) { fprintf(stderr, "ERROR: failed to connect\n"); return -1; } diff --git a/tls/client-tls-ecdhe.c b/tls/client-tls-ecdhe.c index ddeb53c4..265e4ead 100644 --- a/tls/client-tls-ecdhe.c +++ b/tls/client-tls-ecdhe.c @@ -33,7 +33,6 @@ /* wolfSSL */ #include - #define DEFAULT_PORT 11111 #define CERT_FILE "../certs/server-ecc.pem" @@ -42,6 +41,8 @@ #define KEY_FILE "../certs/ecc-client-key.pem" #define CIPHER_LIST "ECDHE-ECDSA-CHACHA20-POLY1305" + + int main(int argc, char** argv) { int sockfd; diff --git a/tls/client-tls-nonblocking.c b/tls/client-tls-nonblocking.c index 768a74c2..31b0737b 100644 --- a/tls/client-tls-nonblocking.c +++ b/tls/client-tls-nonblocking.c @@ -33,12 +33,12 @@ /* wolfSSL */ #include - - #define DEFAULT_PORT 11111 #define CERT_FILE "../certs/ca-cert.pem" + + int main(int argc, char** argv) { int sockfd; @@ -136,9 +136,7 @@ int main(int argc, char** argv) if (wolfSSL_want_read(ssl)) { /* no error, just non-blocking. Carry on. */ printf("Waiting for connection...\n"); - sleep(1); /* cut down on spam */ - continue; } fprintf(stderr, "ERROR: failed to connect to wolfSSL\n"); diff --git a/tls/client-tls-perf.c b/tls/client-tls-perf.c old mode 100755 new mode 100644 diff --git a/tls/client-tls-resume.c b/tls/client-tls-resume.c index 30a40f10..8493b60a 100644 --- a/tls/client-tls-resume.c +++ b/tls/client-tls-resume.c @@ -33,12 +33,12 @@ /* wolfSSL */ #include - - #define DEFAULT_PORT 11111 #define CERT_FILE "../certs/ca-cert.pem" + + int main(int argc, char** argv) { int sockfd; @@ -199,7 +199,8 @@ int main(int argc, char** argv) /* Reconnect to the server */ - if (connect(sockfd, (struct sockaddr*) &servAddr, sizeof(servAddr)) < 0) { + if (connect(sockfd, (struct sockaddr*) &servAddr, sizeof(servAddr)) + == -1) { fprintf(stderr, "ERROR: failed to connect\n"); return -1; } @@ -246,6 +247,9 @@ int main(int argc, char** argv) return -1; } + /* Print to stdout any data the server sends */ + printf("Server: %s\n", buff); + /* Cleanup and return */ diff --git a/tls/client-tls-writedup.c b/tls/client-tls-writedup.c index aa268c6b..f579237f 100644 --- a/tls/client-tls-writedup.c +++ b/tls/client-tls-writedup.c @@ -17,9 +17,9 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ - -/* NOTE: ---------------------------------------------------------------------- + * + * ----------------------------------------------------------------------------- + * NOTE: * wolfSSL needs to be built with --enable-writedup, or else we'll see errors. */ @@ -40,6 +40,10 @@ /* threads */ #include +#define DEFAULT_PORT 11111 + +#define CERT_FILE "../certs/ca-cert.pem" + void* ReadHandler(void* args) @@ -85,10 +89,6 @@ void* WriteHandler(void* args) -#define DEFAULT_PORT 11111 - -#define CERT_FILE "../certs/ca-cert.pem" - int main(int argc, char** argv) { int sockfd; diff --git a/tls/client-tls.c b/tls/client-tls.c index fbe9a29b..3eafe725 100644 --- a/tls/client-tls.c +++ b/tls/client-tls.c @@ -33,12 +33,12 @@ /* wolfSSL */ #include - - #define DEFAULT_PORT 11111 #define CERT_FILE "../certs/ca-cert.pem" + + int main(int argc, char** argv) { int sockfd; diff --git a/tls/server-tcp.c b/tls/server-tcp.c index 7f4658de..a0259db8 100644 --- a/tls/server-tcp.c +++ b/tls/server-tcp.c @@ -30,9 +30,10 @@ #include #include - #define DEFAULT_PORT 11111 + + int main() { int sockfd; @@ -55,6 +56,7 @@ int main() } + /* Initialize the server address struct with zeros */ memset(&servAddr, 0, sizeof(servAddr)); @@ -129,6 +131,9 @@ int main() close(connd); /* Close the connection to the server */ } + printf("Shutdown complete\n"); + + /* Cleanup and return */ close(sockfd); /* Close the socket listening for clients */ diff --git a/tls/server-tls-callback.c b/tls/server-tls-callback.c index aaa0c742..8a21e275 100644 --- a/tls/server-tls-callback.c +++ b/tls/server-tls-callback.c @@ -34,6 +34,11 @@ /* wolfSSL */ #include +#define DEFAULT_PORT 11111 + +#define CERT_FILE "../certs/server-cert.pem" +#define KEY_FILE "../certs/server-key.pem" + int my_IORecv(WOLFSSL* ssl, char* buff, int sz, void* ctx) @@ -135,12 +140,6 @@ int my_IOSend(WOLFSSL* ssl, char* buff, int sz, void* ctx) -#define DEFAULT_PORT 11111 - -#define CERT_FILE "../certs/server-cert.pem" -#define KEY_FILE "../certs/server-key.pem" -#define DH_FILE "../certs/dh2048.pem" - int main() { int sockfd; @@ -195,18 +194,14 @@ int main() return -1; } - /* Set DH params for WOLFSSL_CTX */ - if (wolfSSL_CTX_SetTmpDH_file(ctx, DH_FILE, SSL_FILETYPE_PEM) - != SSL_SUCCESS) { - fprintf(stderr, "ERROR: failed to set DH parameters.\n"); - return -1; - } + /* Register callbacks */ wolfSSL_SetIORecv(ctx, my_IORecv); wolfSSL_SetIOSend(ctx, my_IOSend); + /* Initialize the server address struct with zeros */ memset(&servAddr, 0, sizeof(servAddr)); @@ -291,6 +286,9 @@ int main() close(connd); /* Close the connection to the server */ } + printf("Shutdown complete\n"); + + /* Cleanup and return */ wolfSSL_CTX_free(ctx); /* Free the wolfSSL context object */ diff --git a/tls/server-tls-ecdhe.c b/tls/server-tls-ecdhe.c index eb8beb4e..c85f64cb 100644 --- a/tls/server-tls-ecdhe.c +++ b/tls/server-tls-ecdhe.c @@ -33,13 +33,12 @@ /* wolfSSL */ #include - - #define DEFAULT_PORT 11111 #define CERT_FILE "../certs/server-ecc.pem" #define KEY_FILE "../certs/ecc-key.pem" -#define CIPHER_LIST "ECDHE-ECDSA-CHACHA20-POLY1305" + + int main() { @@ -187,6 +186,9 @@ int main() close(connd); /* Close the connection to the server */ } + printf("Shutdown complete\n"); + + /* Cleanup and return */ wolfSSL_CTX_free(ctx); /* Free the wolfSSL context object */ diff --git a/tls/server-tls-epoll-perf.c b/tls/server-tls-epoll-perf.c old mode 100755 new mode 100644 diff --git a/tls/server-tls-epoll-threaded.c b/tls/server-tls-epoll-threaded.c old mode 100755 new mode 100644 diff --git a/tls/server-tls-nonblocking.c b/tls/server-tls-nonblocking.c index 45250978..60464188 100644 --- a/tls/server-tls-nonblocking.c +++ b/tls/server-tls-nonblocking.c @@ -34,13 +34,12 @@ /* wolfSSL */ #include - - #define DEFAULT_PORT 11111 #define CERT_FILE "../certs/server-cert.pem" #define KEY_FILE "../certs/server-key.pem" -#define DH_FILE "../certs/dh2048.pem" + + int main() { @@ -102,13 +101,6 @@ int main() return -1; } - /* Set DH params for WOLFSSL_CTX */ - if (wolfSSL_CTX_SetTmpDH_file(ctx, DH_FILE, SSL_FILETYPE_PEM) - != SSL_SUCCESS) { - fprintf(stderr, "ERROR: failed to set DH parameters.\n"); - return -1; - } - /* Initialize the server address struct with zeros */ @@ -207,6 +199,9 @@ int main() close(connd); /* Close the connection to the server */ } + printf("Shutdown complete\n"); + + /* Cleanup and return */ wolfSSL_CTX_free(ctx); /* Free the wolfSSL context object */ diff --git a/tls/server-tls-threaded.c b/tls/server-tls-threaded.c index 19c32b5b..b495fef0 100644 --- a/tls/server-tls-threaded.c +++ b/tls/server-tls-threaded.c @@ -33,9 +33,16 @@ /* wolfSSL */ #include -/* Threads */ +/* threads */ #include +#define DEFAULT_PORT 11111 + +#define MAX_CONCURRENT_THREADS 10 + +#define CERT_FILE "../certs/server-cert.pem" +#define KEY_FILE "../certs/server-key.pem" + /* Thread argument package */ @@ -115,14 +122,6 @@ void* ClientHandler(void* args) -#define DEFAULT_PORT 11111 - -#define MAX_CONCURRENT_THREADS 10 - -#define CERT_FILE "../certs/server-cert.pem" -#define KEY_FILE "../certs/server-key.pem" -#define DH_FILE "../certs/dh2048.pem" - int main() { int sockfd; @@ -184,13 +183,6 @@ int main() return -1; } - /* Set DH params for WOLFSSL_CTX */ - if (wolfSSL_CTX_SetTmpDH_file(ctx, DH_FILE, SSL_FILETYPE_PEM) - != SSL_SUCCESS) { - fprintf(stderr, "ERROR: failed to set DH parameters.\n"); - return -1; - } - /* Initialize the server address struct with zeros */ diff --git a/tls/server-tls.c b/tls/server-tls.c index c12e6243..df15a929 100644 --- a/tls/server-tls.c +++ b/tls/server-tls.c @@ -33,13 +33,12 @@ /* wolfSSL */ #include - - #define DEFAULT_PORT 11111 #define CERT_FILE "../certs/server-cert.pem" #define KEY_FILE "../certs/server-key.pem" -#define DH_FILE "../certs/dh2048.pem" + + int main() { @@ -95,13 +94,6 @@ int main() return -1; } - /* Set DH params for WOLFSSL_CTX */ - if (wolfSSL_CTX_SetTmpDH_file(ctx, DH_FILE, SSL_FILETYPE_PEM) - != SSL_SUCCESS) { - fprintf(stderr, "ERROR: failed to set DH parameters.\n"); - return -1; - } - /* Initialize the server address struct with zeros */ @@ -188,6 +180,9 @@ int main() close(connd); /* Close the connection to the server */ } + printf("Shutdown complete\n"); + + /* Cleanup and return */ wolfSSL_CTX_free(ctx); /* Free the wolfSSL context object */