wrapper of the mbed port of Cyassl. It's based of the work of Ashley Mills

Dependencies:   cyassl-lib

Dependents:   TLS_cyassl-Example TLS_cyassl-Example2 HTTPSClientExample2

Fork of TLS_cyassl by Francois Berder

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.

Files at this revision

API Documentation at this revision

Comitter:
feb11
Date:
Mon Sep 16 09:54:45 2013 +0000
Parent:
1:9494492e9bf7
Child:
3:0e5471a26490
Commit message:
removed debug information

Changed in this revision

TLSConnection.cpp Show annotated file Show diff for this revision Revisions of this file
TLSConnection.h Show annotated file Show diff for this revision Revisions of this file
cyassl-lib.lib Show annotated file Show diff for this revision Revisions of this file
dbg.cpp Show diff for this revision Revisions of this file
dbg.h Show diff for this revision Revisions of this file
--- 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;
     }  
 
--- a/TLSConnection.h	Fri Sep 13 12:59:14 2013 +0000
+++ b/TLSConnection.h	Mon Sep 16 09:54:45 2013 +0000
@@ -3,7 +3,8 @@
 
 #include "Socket.h"
 #include "Endpoint.h"
-#include "ssl.h"
+#include "bsd_socket.h"
+#include "cyassl/ssl.h"
 
 /** This class provides a user-friendly interface for the
     axTLS library.
--- a/cyassl-lib.lib	Fri Sep 13 12:59:14 2013 +0000
+++ b/cyassl-lib.lib	Mon Sep 16 09:54:45 2013 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/feb11/code/cyassl-lib2/#d5bd39a52de3
+http://mbed.org/users/feb11/code/cyassl-lib2/#f377303c41be
--- a/dbg.cpp	Fri Sep 13 12:59:14 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,127 +0,0 @@
-/* dbg.cpp */
-/* Copyright (C) 2012 mbed.org, MIT License
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
- * and associated documentation files (the "Software"), to deal in the Software without restriction,
- * including without limitation the rights to use, copy, modify, merge, publish, distribute,
- * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all copies or
- * substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
- * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include "dbg.h"
-
-#include "mbed.h"
-#include "rtos.h"
-
-#include <cstdio>
-#include <cstdarg>
-
-using namespace std;
-
-static Serial debug_pc(USBTX, USBRX);
-
-static char debug_newline[3];
-
-static void debug_lock(bool set)
-{
-  static Mutex* mtx = new Mutex(); //Singleton runtime initialisation to avoid static initialisation chaos problems
-  static bool init = false;
-  if(set)
-  {
-    mtx->lock();
-    if(!init)
-    {
-      strncpy( debug_newline, "\n", 2 );
-      printf("[START]\n");
-      fflush(stdout);
-      init = true;
-    }
-  }
-  else
-  {
-    mtx->unlock();
-  }
-}
-
-void debug_init()
-{
-  debug_lock(true); //Force init
-  debug_lock(false);
-}
-
-void debug_set_newline(const char* newline)
-{
-  debug_lock(true);
-  strncpy( debug_newline, newline, 2 );
-  debug_newline[2] = '\0';
-  debug_lock(false);
-}
-
-void debug_set_speed(int speed)
-{
-  debug_pc.baud(speed);
-}
-
-void debug(int level, const char* module, int line, const char* fmt, ...)
-{
-  debug_lock(true);
-  switch(level)
-  {
-  default:
-  case 1:
-    printf("[ERROR]");
-    break;
-  case 2:
-    printf("[WARN]");
-    break;
-  case 3:
-    printf("[INFO]");
-    break;
-  case 4:
-    printf("[DBG]");
-    break;
-  }
-
-  printf(" Module %s - Line %d: ", module, line);
-
-  va_list argp;
-
-  va_start(argp, fmt);
-  vprintf(fmt, argp);
-  va_end(argp);
-
-  printf(debug_newline);
-
-  fflush(stdout);
-
-  debug_lock(false);
-
-}
-
-void debug_error(const char* module, int line, int ret)
-{
-  debug_lock(true);
-  printf("[RC] Module %s - Line %d : Error %d\n", module, line, ret);
-  fflush(stdout);
-  debug_lock(false);
-}
-
-void debug_exact(const char* fmt, ...)
-{
-  debug_lock(true);
-  va_list argp;
-
-  va_start(argp, fmt);
-  vprintf(fmt, argp);
-  va_end(argp);
-  debug_lock(false);
-}
--- a/dbg.h	Fri Sep 13 12:59:14 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,79 +0,0 @@
-/* dbg.h */
-/* Copyright (C) 2012 mbed.org, MIT License
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
- * and associated documentation files (the "Software"), to deal in the Software without restriction,
- * including without limitation the rights to use, copy, modify, merge, publish, distribute,
- * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all copies or
- * substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
- * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#ifndef DBG_H_
-#define DBG_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-void debug_init(void);
-void debug(int level, const char* module, int line, const char* fmt, ...);
-void debug_set_newline(const char* newline);
-void debug_set_speed(int speed);
-void debug_error(const char* module, int line, int ret);
-void debug_exact(const char* fmt, ...);
-
-#define DBG_INIT() do{ debug_init(); }while(0)
-
-#define DBG_SET_NEWLINE( x ) do{ debug_set_newline(x); }while(0)
-
-#define DBG_SET_SPEED( x ) do{ debug_set_speed(x); }while(0)
-
-#if __DEBUG__ > 0
-#ifndef __MODULE__
-#error "__MODULE__ must be defined"
-#endif
-#endif
-
-#if __DEBUG__ >= 1
-#define ERR(...) do{ debug(1, __MODULE__, __LINE__, __VA_ARGS__); }while(0)
-#else
-#define ERR(...) do{ }while(0)
-#endif
-
-#if __DEBUG__ >= 2
-#define WARN(...) do{ debug(2, __MODULE__, __LINE__, __VA_ARGS__); }while(0)
-#else
-#define WARN(...) do{ }while(0)
-#endif
-
-#if __DEBUG__ >= 3
-#define INFO(...) do{ debug(3, __MODULE__, __LINE__, __VA_ARGS__); }while(0)
-#define CHECK(ret) do{ if(ret){ debug_error(__MODULE__, __LINE__, ret); } }while(0)
-#else
-#define INFO(...) do{ }while(0)
-#define CHECK(ret) do{ }while(0)
-#endif
-
-#if __DEBUG__ >= 4
-#define DBG(...) do{ debug(4, __MODULE__, __LINE__, __VA_ARGS__); }while(0)
-#define DBGX(...) do{ debug_exact(__VA_ARGS__); }while(0)
-#else
-#define DBG(...) do{ }while(0)
-#define DBGX(...) do{ }while(0)
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* DBG_H_ */