Execution example of ssl access
Dependencies: CyaSSL EthernetInterface mbed-rtos mbed
Fork of ssl_access_exe by
Revision 6:1b761393c52c, committed 2015-07-22
- Comitter:
- thursday1024
- Date:
- Wed Jul 22 08:23:57 2015 +0000
- Parent:
- 5:962734db89e5
- Commit message:
- ssl access executable
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Dec 08 13:17:25 2014 +0000 +++ b/main.cpp Wed Jul 22 08:23:57 2015 +0000 @@ -1,15 +1,16 @@ +// ssl_access_exe main.cpp #include "mbed.h" #include "EthernetInterface.h" -/*** SSL #include <cyassl/ssl.h> ***/ +#include <cyassl/ssl.h> -#define PORT 80 /*** SSL 443 ***/ +#define PORT 443 #define err_sys(m) puts(m) TCPSocketConnection socket; -/*** SSL + static int SocketReceive(CYASSL* ssl, char *buf, int sz, void *ctx) { int n ; @@ -33,7 +34,7 @@ } else printf("SocketSend:%d/%d\n", n, sz); return n ; } -***/ + EthernetInterface eth; @@ -42,33 +43,29 @@ char server_ip[20] ; eth.init(); //Use DHCP - printf("===== Simple TCP Client ========\n") ; - /*** SSL + //printf("===== Simple TCP Client ========\n") ; printf("===== Simple SSL Client ========\n") ; - ***/ - + while(1) { if(eth.connect()== 0)break ; wait(0.1); } printf("Client IP: %s\n", eth.getIPAddress()); - /*** SSL + CYASSL_CTX* ctx = 0; CYASSL* ssl = 0; CYASSL_METHOD* method = CyaTLSv1_2_client_method(); - ***/ - + + /* Initialize CyaSSL Context */ - /*** SSL ctx = CyaSSL_CTX_new(method); if (ctx == NULL) err_sys("unable to get ctx"); CyaSSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, 0); CyaSSL_SetIORecv(ctx, SocketReceive) ; CyaSSL_SetIOSend(ctx, SocketSend) ; - end SSL ***/ socket.set_blocking(false, 300) ; printf("Server IP: ") ; @@ -86,7 +83,6 @@ } printf("TCP Connected\n") ; - /*** SSL ssl = CyaSSL_new(ctx); if (ssl == NULL) err_sys("unable to get SSL object"); @@ -97,32 +93,32 @@ err_sys("SSL Connection Error"); } printf("SSL Connected\n") ; - ***/ + char msg[] = "GET /congrats.html HTTP/1.0\r\nConnection: Close\r\n\r\n" ; // const char msg[] = "Hello World\r\n" ; if ( - /*** SSL - CyaSSL_write(ssl, msg, sizeof(msg)-1) != (sizeof(msg)-1)) ***/ - socket.send(msg, sizeof(msg)-1) != (sizeof(msg)-1)) + + CyaSSL_write(ssl, msg, sizeof(msg)-1) != (sizeof(msg)-1)) + //socket.send(msg, sizeof(msg)-1) != (sizeof(msg)-1)) err_sys("CyaSSL_write failed"); char buf[1024]; int n ; puts("Server Response:\n") ; do { - n = /*** SSL CyaSSL_read(ssl, buf, sizeof(buf)-1); ***/ - socket.receive(buf, sizeof(buf)-1); + n = CyaSSL_read(ssl, buf, sizeof(buf)-1); + //socket.receive(buf, sizeof(buf)-1); if (n >= 0) { buf[n] = 0; printf("%s", buf); } else break ; } while(n > 0) ; puts("=== === === ===") ; - /*** SSL CyaSSL_free(ssl) ; ***/ + CyaSSL_free(ssl) ; socket.close(); - /*** SSL CyaSSL_CTX_free(ctx) ; ***/ + CyaSSL_CTX_free(ctx) ; eth.disconnect(); }