Example TLS client with wolfSSL, with cert
Dependencies: EthernetInterface NTPClient SDFileSystem mbed-rtos mbed wolfSSL
Revision 4:ebcf8e2d846a, committed 2015-07-21
- Comitter:
- wolfSSL
- Date:
- Tue Jul 21 22:49:46 2015 +0000
- Parent:
- 3:25d42ccf2f12
- Child:
- 5:26b87ccd43d1
- Commit message:
- client-tls without server verification
Changed in this revision
client-tls.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/client-tls.cpp Tue Jul 21 11:38:01 2015 +0000 +++ b/client-tls.cpp Tue Jul 21 22:49:46 2015 +0000 @@ -21,8 +21,6 @@ #include "mbed.h" #include "EthernetInterface.h" -#include "NTPClient.h" -#include "SDFileSystem.h" #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -32,16 +30,6 @@ #define MAXDATASIZE (1024*4) -#if !defined(WOLFSSL_NO_VERIFYSERVER) - #if defined(NO_FILESYSTEM) - #define USE_CERT_BUFFERS_2048 - #include <wolfssl/certs_test.h> - #else - SDFileSystem sdCard(PTE3, PTE1, PTE2, PTE4, "sd"); - const char* certFile = "/sd/ca-cert.pem"; - #endif -#endif - static int SocketReceive(WOLFSSL* ssl, char *buf, int sz, void *sock) { return ((TCPSocketConnection *)sock)->receive(buf, sz) ; @@ -147,19 +135,6 @@ wolfSSL_SetIORecv(ctx, SocketReceive) ; wolfSSL_SetIOSend(ctx, SocketSend) ; -#ifdef WOLFSSL_NO_VERIFYSERVER - wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, 0); -#else - #ifndef NO_FILESYSTEM - if (wolfSSL_CTX_load_verify_locations(ctx, certFile,0) != SSL_SUCCESS) - printf("can't load ca file\n"); - #else - if (wolfSSL_CTX_load_verify_buffer(ctx, ca_cert_der_2048, - sizeof_ca_cert_der_2048, SSL_FILETYPE_ASN1) != SSL_SUCCESS) - printf("can't load ca data"); - #endif -#endif - if ((ssl = wolfSSL_new(ctx)) == NULL) { printf("wolfSSL_new error.\n"); return EXIT_FAILURE; @@ -191,29 +166,22 @@ { char server_addr[40] ; char server_port[10] ; - + wolfSSL_Init(); /* initialize wolfSSL */ /* wolfSSL_Debugging_ON(); */ EthernetInterface eth; TCPSocketConnection socket; + eth.init(); //Use DHCP eth.connect(); printf("Client Addr: %s\n", eth.getIPAddress()); -#ifndef WOLFSSL_NO_VERIFYSERVER - NTPClient ntp; - if(ntp.setTime("ntp.jst.mfeed.ad.jp") != 0){ - printf("NTP Error\n") ; - return ; - } -#endif - 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) ; + wait(1.0); } printf("TCP Connected\n") ;