A fork of the TLS_cyassl embedded SSL library with certificate validation disabled.

Dependencies:   cyassl-lib

Fork of TLS_cyassl by Francois Berder

Revision:
2:63ad554f6ca4
Parent:
1:9494492e9bf7
Child:
3:0e5471a26490
--- a/TLSConnection.cpp	Fri Sep 13 12:59:14 2013 +0000
+++ b/TLSConnection.cpp	Mon Sep 16 09:54:45 2013 +0000
@@ -1,32 +1,37 @@
-#define __DEBUG__ 4 //Maximum verbosity
-#ifndef __MODULE__
-#define __MODULE__ "TLSConnection.cpp"
-#endif
-
-#define DEBUG_CYASSL 1
-#include "dbg.h"
 #include "TLSConnection.h"
 #include <stdlib.h>
 #include <stdio.h>
-#include "bsd_socket.h"
 #include "cert.h"
-#undef NO_CERTS
-#undef NO_FILESYSTEM
-#include "ssl.h"
-#include "logging.h"
+#include <string.h>
 
+static int receiveFunc(CYASSL* ssl, char *buf, int sz, void *ctx)
+{    
+    int fd = *(int*)ctx;
+    fd_set rfds;
+    FD_ZERO(&rfds);
+    FD_SET(fd, &rfds);
+    
+    if (lwip_select(FD_SETSIZE, &rfds, NULL, NULL, NULL) < 0)
+        return -1;
+            
+    return lwip_recv(fd, buf, sz, 0);
+}
+
+static int sendFunc(CYASSL* ssl, char *buf, int sz, void *ctx)
+{
+    int fd = *(int*)ctx;
+    fd_set wfds;
+    FD_ZERO(&wfds);
+    FD_SET(fd, &wfds);
+    
+    if (lwip_select(FD_SETSIZE, NULL, &wfds, NULL, NULL) < 0)
+        return -1;
+            
+    return lwip_send(fd, buf, sz, 0);    
+}
 
 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():
     Socket(),
     Endpoint(),
@@ -36,9 +41,6 @@
 {
 }
 
-void debugCallback(const int logLevel,const char *const logMessage) {
-   DBG(logMessage);
-}
 
 bool TLSConnection::connect(const char *host)
 {
@@ -54,9 +56,8 @@
     }
 
     CyaSSL_Init();
-    CyaSSL_Debugging_ON();
-
-    CyaSSL_SetLoggingCb(&debugCallback);
+    CyaSSL_Debugging_OFF();
+    
     CYASSL_METHOD* method = CyaTLSv1_2_client_method();
     if(method == NULL)
     {
@@ -68,6 +69,8 @@
     {
         return false;
     }    
+    CyaSSL_SetIOSend(_ssl_ctx, &sendFunc);
+    CyaSSL_SetIORecv(_ssl_ctx, &receiveFunc);
     CyaSSL_CTX_load_verify_buffer(_ssl_ctx,(unsigned char*)root_cert, root_cert_len,SSL_FILETYPE_ASN1);
 
     _ssl = CyaSSL_new(_ssl_ctx);
@@ -80,7 +83,7 @@
     int result = CyaSSL_connect(_ssl);
     if(result!=SSL_SUCCESS) 
     {
-        printError(_ssl,result);
+        printf("error=%d\n", result);
         return false;
     }