Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
983 changes: 968 additions & 15 deletions tls/README.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions tls/client-tls-callback.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <unistd.h>

/* wolfSSL */
#include <wolfssl/options.h>
#include <wolfssl/ssl.h>

#define DEFAULT_PORT 11111
Expand Down
1 change: 1 addition & 0 deletions tls/client-tls-ecdhe.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <unistd.h>

/* wolfSSL */
#include <wolfssl/options.h>
#include <wolfssl/ssl.h>

#define DEFAULT_PORT 11111
Expand Down
17 changes: 16 additions & 1 deletion tls/client-tls-nonblocking.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <unistd.h>

/* wolfSSL */
#include <wolfssl/options.h>
#include <wolfssl/ssl.h>

#define DEFAULT_PORT 11111
Expand Down Expand Up @@ -106,7 +107,7 @@ int main(int argc, char** argv)

/* Get the server IPv4 address from the command line call */
if (inet_pton(AF_INET, argv[1], &servAddr.sin_addr) != 1) {
fprintf(stderr, "ERROR: invalid Address\n");
fprintf(stderr, "ERROR: invalid address\n");
return -1;
}

Expand Down Expand Up @@ -164,6 +165,20 @@ int main(int argc, char** argv)



/* Read the server data into our buff array */
memset(buff, 0, sizeof(buff));
while (wolfSSL_read(ssl, buff, sizeof(buff)-1) == -1) {
if (wolfSSL_want_read(ssl)) {
/* no error, just non-blocking. Carry on. */
continue;
}
fprintf(stderr, "ERROR: failed to read\n");
return -1;
}

/* Print to stdout any data the server sends */
printf("Server: %s\n", buff);



/* Cleanup and return */
Expand Down
10 changes: 6 additions & 4 deletions tls/client-tls-resume.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <unistd.h>

/* wolfSSL */
#include <wolfssl/options.h>
#include <wolfssl/ssl.h>

#define DEFAULT_PORT 11111
Expand All @@ -55,6 +56,7 @@ int main(int argc, char** argv)
WOLFSSL* sslRes;



/* Check for proper calling convention */
if (argc != 2) {
printf("usage: %s <IPv4 address>\n", argv[0]);
Expand Down Expand Up @@ -151,7 +153,7 @@ int main(int argc, char** argv)

/* Read the server data into our buff array */
memset(buff, 0, sizeof(buff));
if (wolfSSL_read(ssl, buff, sizeof(buff)-1) < 0) {
if (wolfSSL_read(ssl, buff, sizeof(buff)-1) == -1) {
fprintf(stderr, "ERROR: failed to read\n");
return -1;
}
Expand Down Expand Up @@ -221,7 +223,7 @@ int main(int argc, char** argv)
printf("Session ID reused; Successful resume.\n");
}
else {
printf("Session ID not reused; Successful resume.\n");
printf("Session ID not reused; Failed resume.\n");
}


Expand All @@ -242,7 +244,7 @@ int main(int argc, char** argv)

/* Read the server data into our buff array */
memset(buff, 0, sizeof(buff));
if (wolfSSL_read(sslRes, buff, sizeof(buff)-1) < 0) {
if (wolfSSL_read(sslRes, buff, sizeof(buff)-1) == -1) {
fprintf(stderr, "ERROR: failed to read\n");
return -1;
}
Expand All @@ -253,7 +255,7 @@ int main(int argc, char** argv)


/* Cleanup and return */
wolfSSL_free(ssl); /* Free the wolfSSL object */
wolfSSL_free(sslRes); /* Free the wolfSSL object */
wolfSSL_CTX_free(ctx); /* Free the wolfSSL context object */
wolfSSL_Cleanup(); /* Cleanup the wolfSSL environment */
close(sockfd); /* Close the connection to the server */
Expand Down
15 changes: 9 additions & 6 deletions tls/client-tls-writedup.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,8 @@
#include <unistd.h>

/* wolfSSL */
#include <wolfssl/ssl.h>
#include <wolfssl/options.h>

/* check for writedup */
#ifndef HAVE_WRITE_DUP
#error "wolfSSL must be configured and installed with --enable-writedup"
#endif
#include <wolfssl/ssl.h>

/* threads */
#include <pthread.h>
Expand Down Expand Up @@ -111,6 +106,14 @@ int main(int argc, char** argv)



/* check for writedup */
#ifndef HAVE_WRITE_DUP
#warning wolfSSL must be configured and installed with --enable-writedup
fprintf(stderr, "wolfSSL must be configured and installed with "
"--enable-writedup");
return -1;
#endif

/* Check for proper calling convention */
if (argc != 2) {
printf("usage: %s <IPv4 address>\n", argv[0]);
Expand Down
1 change: 1 addition & 0 deletions tls/client-tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <unistd.h>

/* wolfSSL */
#include <wolfssl/options.h>
#include <wolfssl/ssl.h>

#define DEFAULT_PORT 11111
Expand Down
2 changes: 1 addition & 1 deletion tls/server-tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ int main()

/* Write our reply into buff */
memset(buff, 0, sizeof(buff));
memcpy(buff, "I hear ya fa shizzle!\n", sizeof(buff));
strcpy(buff, "I hear ya fa shizzle!\n");
len = strnlen(buff, sizeof(buff));

/* Reply back to the client */
Expand Down
3 changes: 2 additions & 1 deletion tls/server-tls-callback.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <unistd.h>

/* wolfSSL */
#include <wolfssl/options.h>
#include <wolfssl/ssl.h>

#define DEFAULT_PORT 11111
Expand Down Expand Up @@ -270,7 +271,7 @@ int main()

/* Write our reply into buff */
memset(buff, 0, sizeof(buff));
memcpy(buff, "I hear ya fa shizzle!\n", sizeof(buff));
strcpy(buff, "I hear ya fa shizzle!\n");
len = strnlen(buff, sizeof(buff));

/* Reply back to the client */
Expand Down
3 changes: 2 additions & 1 deletion tls/server-tls-ecdhe.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <unistd.h>

/* wolfSSL */
#include <wolfssl/options.h>
#include <wolfssl/ssl.h>

#define DEFAULT_PORT 11111
Expand Down Expand Up @@ -172,7 +173,7 @@ int main()

/* Write our reply into buff */
memset(buff, 0, sizeof(buff));
memcpy(buff, "I hear ya fa shizzle!\n", sizeof(buff));
strcpy(buff, "I hear ya fa shizzle!\n");
len = strnlen(buff, sizeof(buff));

/* Reply back to the client */
Expand Down
12 changes: 11 additions & 1 deletion tls/server-tls-nonblocking.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <unistd.h>

/* wolfSSL */
#include <wolfssl/options.h>
#include <wolfssl/ssl.h>

#define DEFAULT_PORT 11111
Expand Down Expand Up @@ -142,6 +143,12 @@ int main()
return -1;
}

/* Set the connection options to use nonblocking I/O */
if (fcntl(connd, F_SETFL, O_NONBLOCK) == -1) {
fprintf(stderr, "ERROR: failed to set socket options\n");
return -1;
}

/* Create a WOLFSSL object */
if ((ssl = wolfSSL_new(ctx)) == NULL) {
fprintf(stderr, "ERROR: failed to create WOLFSSL object\n");
Expand All @@ -151,6 +158,9 @@ int main()
/* Attach wolfSSL to the socket */
wolfSSL_set_fd(ssl, connd);

/* make wolfSSL object nonblocking */
wolfSSL_set_using_nonblock(ssl, 1);

printf("Client connected successfully\n");


Expand Down Expand Up @@ -179,7 +189,7 @@ int main()

/* Write our reply into buff */
memset(buff, 0, sizeof(buff));
memcpy(buff, "I hear ya fa shizzle!\n", sizeof(buff));
strcpy(buff, "I hear ya fa shizzle!\n");
len = strnlen(buff, sizeof(buff));

/* Reply back to the client */
Expand Down
7 changes: 4 additions & 3 deletions tls/server-tls-threaded.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,19 @@
#include <unistd.h>

/* wolfSSL */
#include <wolfssl/options.h>
#include <wolfssl/ssl.h>

/* threads */
#include <pthread.h>

#define DEFAULT_PORT 11111

#define MAX_CONCURRENT_THREADS 10

#define CERT_FILE "../certs/server-cert.pem"
#define KEY_FILE "../certs/server-key.pem"

#define MAX_CONCURRENT_THREADS 10



/* Thread argument package */
Expand Down Expand Up @@ -101,7 +102,7 @@ void* ClientHandler(void* args)

/* Write our reply into buff */
memset(buff, 0, sizeof(buff));
memcpy(buff, "I hear ya fa shizzle!\n", sizeof(buff));
strcpy(buff, "I hear ya fa shizzle!\n");
len = strnlen(buff, sizeof(buff));

/* Reply back to the client */
Expand Down
3 changes: 2 additions & 1 deletion tls/server-tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <unistd.h>

/* wolfSSL */
#include <wolfssl/options.h>
#include <wolfssl/ssl.h>

#define DEFAULT_PORT 11111
Expand Down Expand Up @@ -164,7 +165,7 @@ int main()

/* Write our reply into buff */
memset(buff, 0, sizeof(buff));
memcpy(buff, "I hear ya fa shizzle!\n", sizeof(buff));
strcpy(buff, "I hear ya fa shizzle!\n");
len = strnlen(buff, sizeof(buff));

/* Reply back to the client */
Expand Down