ssl_access (http->https)
Dependencies: CyaSSL EthernetInterface mbed-rtos mbed
Fork of ssl_access by
Diff: main.cpp
- Revision:
- 2:29a1370416cb
- Parent:
- 1:ac91b4f8d818
- Child:
- 5:962734db89e5
diff -r ac91b4f8d818 -r 29a1370416cb main.cpp --- a/main.cpp Wed Oct 08 05:04:36 2014 +0000 +++ b/main.cpp Mon Dec 08 05:10:41 2014 +0000 @@ -3,9 +3,9 @@ /*** SSL #include <cyassl/ssl.h> ***/ -const int PORT = 80 /*** SSL 443 end SSL ***/ ; +#define PORT 80 /*** SSL 443 ***/ -#define err_sys(m) { puts(m) ; } +#define err_sys(m) puts(m) TCPSocketConnection socket; @@ -33,21 +33,32 @@ } else printf("SocketSend:%d/%d\n", n, sz); return n ; } -end SSL ***/ +***/ EthernetInterface eth; -void net_main(void const *av) +main() { char server_ip[20] ; + + eth.init(); //Use DHCP + printf("===== Simple TCP Client ========\n") ; + /*** SSL + 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(); - end SSL ***/ - - + ***/ /* Initialize CyaSSL Context */ /*** SSL @@ -61,9 +72,14 @@ socket.set_blocking(false, 300) ; printf("Server IP: ") ; - scanf("%s", server_ip) ; - puts(server_ip) ; - + for(int i=0; i<sizeof(server_ip); i++) { + if((server_ip[i] = getchar()) == '\r') { + server_ip[i] = '\0' ; + putchar('\n') ; + break ; + } else putchar(server_ip[i]) ; + } + while (socket.connect(server_ip, PORT) < 0) { printf("Unable to connect to (%s) on port (%d)\n", server_ip, PORT); wait(1); @@ -86,7 +102,9 @@ char msg[] = "GET / HTTP/1.0\r\nConnection: Close\r\n\r\n" ; // const char msg[] = "Hello World\r\n" ; - if (/*** SSL CyaSSL_write(ssl, end SSL***/ + if ( + /*** SSL + CyaSSL_write(ssl, msg, sizeof(msg)-1) != (sizeof(msg)-1)) ***/ socket.send(msg, sizeof(msg)-1) != (sizeof(msg)-1)) err_sys("CyaSSL_write failed"); @@ -94,12 +112,10 @@ int n ; puts("Server Response:\n") ; do { - n = /*** SSL CyaSSL_read(ssl, end SSL ***/ + n = /*** SSL CyaSSL_read(ssl, buf, sizeof(buf)-1); ***/ socket.receive(buf, sizeof(buf)-1); if (n >= 0) { - buf[n] = 0; - //printf("%d,", n) ; printf("%s", buf); } else err_sys("CyaSSL_read failed"); @@ -110,22 +126,3 @@ /*** SSL CyaSSL_CTX_free(ctx) ; ***/ eth.disconnect(); } - - -main() -{ - - printf("===== Simple TCP Client ========\n") ; - /* CyaSSL_Debugging_ON() ; */ - - eth.init(); //Use DHCP - eth.connect(); - printf("Client IP: %s\n", eth.getIPAddress()); - -#define STACK_SIZE 12000 - Thread t(net_main, NULL, osPriorityNormal, STACK_SIZE); - - while (true) { - Thread::wait(1000); - } -} \ No newline at end of file