Example TLS client with wolfSSL
Dependencies: EthernetInterface-FRDM-k64F mbed-rtos mbed wolfSSL-TLS13-Beta Example-client-tls
Dependents: Example-client-tls
Revision 6:12068e6dc456, committed 2017-05-30
- Comitter:
- wolfSSL
- Date:
- Tue May 30 06:16:51 2017 +0000
- Parent:
- 5:76ad456ac3f0
- Child:
- 7:15faa4a16892
- Commit message:
- Example client for TLS1.3 beta
Changed in this revision
--- a/EthernetInterface.lib Thu Apr 28 01:07:49 2016 +0000 +++ b/EthernetInterface.lib Tue May 30 06:16:51 2017 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/EthernetInterface/#4d7bff17a592 +http://mbed.org/users/mbed_official/code/EthernetInterface/#8de6fe68dc06
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Example-client-tls.lib Tue May 30 06:16:51 2017 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/wolfSSL/code/Example-client-tls/#76ad456ac3f0
--- a/client-tls.cpp Thu Apr 28 01:07:49 2016 +0000 +++ b/client-tls.cpp Tue May 30 06:16:51 2017 +0000 @@ -1,6 +1,6 @@ /* client-tcp.c * - * Copyright (C) 2006-2015 wolfSSL Inc. + * Copyright (C) 2006-2017 wolfSSL Inc. * * This file is part of wolfSSL. (formerly known as CyaSSL) * @@ -43,7 +43,7 @@ static int getline(char *prompt, char *buff, int size) { int sz ; - + printf("%s", prompt) ; for(sz = 0 ; (sz < size) && ((*buff = getchar()) != '\r'); sz++, buff++) { putchar(*buff) ; @@ -84,7 +84,7 @@ /* * clients initial contact with server. Socket to connect to: sock */ - int ClientGreet(TCPSocketConnection *socket, WOLFSSL *ssl) +int ClientGreet(TCPSocketConnection *socket, WOLFSSL *ssl) { /* data to send to the server, data recieved from the server */ char sendBuff[MAXDATASIZE], rcvBuff[MAXDATASIZE] = {0}; @@ -98,21 +98,16 @@ printf("Write error[%d]\n", ret, wc_GetErrorString(ret)); return EXIT_FAILURE; } - printf("Recieved:\n"); - while(1) { - if ((ret = wolfSSL_read(ssl, rcvBuff, sizeof(rcvBuff)-1)) < 0) { - if(ret == 0)break ; - /* the server failed to send data, or error trying */ - ret = wolfSSL_get_error(ssl, 0); - printf("Read error[%d], %s\n", ret, wc_GetErrorString(ret)); - return EXIT_FAILURE; - } - rcvBuff[ret] = '\0' ; - printf("%s", rcvBuff); - if((rcvBuff[ret-3] == '\n')&& - (rcvBuff[ret-2] == '\n')&& - (rcvBuff[ret-1] == '\n'))break ; + + if ((ret = wolfSSL_read(ssl, rcvBuff, sizeof(rcvBuff)-1)) < 0) { + /* the server failed to send data, or error trying */ + ret = wolfSSL_get_error(ssl, 0); + printf("Read error[%d], %s\n", ret, wc_GetErrorString(ret)); + return EXIT_FAILURE; } + rcvBuff[ret] = '\0' ; + printf("Recieved: %s\n", rcvBuff); + return ret; } @@ -127,7 +122,7 @@ int ret = 0; /* create and initiLize WOLFSSL_CTX structure */ - if ((ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method())) == NULL) { + if ((ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method())) == NULL) { printf("SSL_CTX_new error.\n"); return EXIT_FAILURE; } @@ -150,7 +145,7 @@ } else { ret = wolfSSL_get_error(ssl, 0); printf("TLS Connect error[%d], %s\n", ret, wc_GetErrorString(ret)); - return EXIT_FAILURE; + return EXIT_FAILURE; } /* frees all data before client termination */ wolfSSL_free(ssl); @@ -167,7 +162,7 @@ { char server_addr[40] ; char server_port[10] ; - + printf("Starting TLS Client,...\n") ; wolfSSL_Init(); /* initialize wolfSSL */ /* wolfSSL_Debugging_ON(); */ @@ -183,7 +178,7 @@ getline("Server Addr: ", server_addr, sizeof(server_addr)) ; getline("Server Port: ", server_port, sizeof(server_port)) ; - + while (socket.connect(server_addr, atoi(server_port)) < 0) { printf("Unable to connect to (%s) on port (%s)\n", server_addr, server_port); wait(1.0);
--- a/mbed-rtos.lib Thu Apr 28 01:07:49 2016 +0000 +++ b/mbed-rtos.lib Tue May 30 06:16:51 2017 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed-rtos/#bdd541595fc5 +http://mbed.org/users/mbed_official/code/mbed-rtos/#58563e6cba1e
--- a/mbed.bld Thu Apr 28 01:07:49 2016 +0000 +++ b/mbed.bld Tue May 30 06:16:51 2017 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/082adc85693f \ No newline at end of file +https://mbed.org/users/mbed_official/code/mbed/builds/86740a56073b \ No newline at end of file
--- a/wolfSSL.lib Thu Apr 28 01:07:49 2016 +0000 +++ b/wolfSSL.lib Tue May 30 06:16:51 2017 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/users/wolfSSL/code/wolfSSL/#1b0d80432c79 +http://developer.mbed.org/users/wolfSSL/code/wolfSSL/#80fb167dafdf