wrapper of the mbed port of Cyassl. It's based of the work of Ashley Mills
Dependents: TLS_cyassl-Example TLS_cyassl-Example2 HTTPSClientExample2
Fork of TLS_cyassl by
Import programTLS_cyassl-Example
This program shows how to use TLS_cyassl to connect to mbed.org
Import programTLS_cyassl-Example2
This example show how to create a small TLS server using the TLS_cyassl library.
Diff: TLSConnection.cpp
- Revision:
- 1:9494492e9bf7
- Parent:
- 0:815067fd66c9
- Child:
- 2:63ad554f6ca4
--- a/TLSConnection.cpp Thu Sep 12 16:37:08 2013 +0000 +++ b/TLSConnection.cpp Fri Sep 13 12:59:14 2013 +0000 @@ -3,6 +3,7 @@ #define __MODULE__ "TLSConnection.cpp" #endif +#define DEBUG_CYASSL 1 #include "dbg.h" #include "TLSConnection.h" #include <stdlib.h> @@ -14,15 +15,16 @@ #include "ssl.h" #include "logging.h" + const static int HTTPS_PORT = 443; void printError(CYASSL *ssl, int resultCode) { -/* + int err = CyaSSL_get_error(ssl, resultCode); char errorString[80]; CyaSSL_ERR_error_string(err, errorString); printf("Error: CyaSSL_write %s\n", errorString); -*/ + } TLSConnection::TLSConnection(): @@ -35,7 +37,7 @@ } void debugCallback(const int logLevel,const char *const logMessage) { - //DBG(logMessage); + DBG(logMessage); } bool TLSConnection::connect(const char *host) @@ -50,31 +52,29 @@ close(); return false; } - + CyaSSL_Init(); CyaSSL_Debugging_ON(); CyaSSL_SetLoggingCb(&debugCallback); - CYASSL_METHOD* method = CyaTLSv1_2_client_method(); - if(method == NULL) + if(method == NULL) { return false; } - + _ssl_ctx = CyaSSL_CTX_new(method); if(_ssl_ctx == NULL) { return false; } CyaSSL_CTX_load_verify_buffer(_ssl_ctx,(unsigned char*)root_cert, root_cert_len,SSL_FILETYPE_ASN1); - + _ssl = CyaSSL_new(_ssl_ctx); if(_ssl == NULL) { return false; } - CyaSSL_set_fd(_ssl, _sock_fd); int result = CyaSSL_connect(_ssl); @@ -96,12 +96,18 @@ int TLSConnection::send_all(char *data, int length) { - return 0; + if(!_is_connected) + return 0; + + return CyaSSL_write(_ssl, data, length); } int TLSConnection::receive(char *data, int length) { - return 0; + if(!_is_connected) + return 0; + + return CyaSSL_read(_ssl, data, length); } bool TLSConnection::close(bool shutdown)