A HTTP/HTTPS Client for the mbed networking/CyaSSL ssl library

Dependents:   Anpi dropbox_access php_access_auth TwitterReader ... more

Fork of HTTPClient by Donatien Garnier

HTTP and HTTPS Client Class with wolfSSL, embedded SSL library.

/media/uploads/wolfSSL/wolfssl_logo.png

The class was forked from http://mbed.org/users/donatien/code/HTTPClient/

It, now, accepts url both with "http://" and "https://".

Allocate caller thread with 16kbytes or larger stack for "https" requests.

Rest of the API stays compatible with HTTPClient.

For more about the library, see http://www.wolfssl.com. http://wolfssl.com/yaSSL/Docs.html.

Extended methods:

  • HTTPResult basicAuth(const char* user, const char* password); /* set id/passwd for basic Authentication */
  • void setHeader(char *header) ; /* set http headers */
  • HTTPResult setSSLversion(int minorV) ; /* set SSL/TLS version. 0: SSL3, 1: TLS1.0, 2: TLS1.1, 3: TLS1.2 */

Files at this revision

API Documentation at this revision

Comitter:
wolfSSL
Date:
Fri Jun 26 00:39:47 2015 +0000
Parent:
30:a9ecee69c6b5
Child:
32:9aadb8a34e80
Commit message:
with wolfSSL 3.6.0

Changed in this revision

CyaSSL.lib Show diff for this revision Revisions of this file
HTTPClient.cpp Show annotated file Show diff for this revision Revisions of this file
HTTPClient.h Show annotated file Show diff for this revision Revisions of this file
--- a/CyaSSL.lib	Fri Dec 05 07:03:47 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/wolfSSL/code/CyaSSL/#64d4f7cb83d5
--- a/HTTPClient.cpp	Fri Dec 05 07:03:47 2014 +0000
+++ b/HTTPClient.cpp	Fri Jun 26 00:39:47 2015 +0000
@@ -24,12 +24,13 @@
 #define DBG(x, ...) std::printf("[HTTPClient : DBG]"x"\r\n", ##__VA_ARGS__);
 #define WARN(x, ...) std::printf("[HTTPClient : WARN]"x"\r\n", ##__VA_ARGS__);
 #define ERR(x, ...) std::printf("[HTTPClient : ERR]"x"\r\n", ##__VA_ARGS__);
-
+#define WOLF_DEBUG_ON    wolfSSL_Debugging_ON() ;
 #else
 //Disable debug
 #define DBG(x, ...)
 #define WARN(x, ...)
 #define ERR(x, ...)
+#define WOLF_DEBUG_ON 
 
 #endif
 
@@ -43,10 +44,10 @@
 
 #include <cstring>
 
-#include  <../CyaSSL/cyassl/ctaocrypt/settings.h>
-#include <../CyaSSL/cyassl/ctaocrypt/types.h>
-#include <../CyaSSL/cyassl/internal.h>
-#include <../CyaSSL/cyassl/ssl.h>
+#include  <../wolfSSL/wolfssl/wolfcrypt/settings.h>
+#include <../wolfSSL/wolfssl/wolfcrypt/types.h>
+#include <../wolfSSL/wolfssl/internal.h>
+#include <../wolfSSL/wolfssl/ssl.h>
 
 #include "HTTPClient.h"
 #include "TCPSocketConnection.h"
@@ -57,7 +58,7 @@
 static char send_buf[SEND_BUF_SIZE] ;
 static char *send_buf_p ;
 
-static int SocketReceive(CYASSL* ssl, char *buf, int sz, void *ctx)
+static int SocketReceive(WOLFSSL* ssl, char *buf, int sz, void *ctx)
 {
     int n ;
     int i ;
@@ -72,7 +73,7 @@
     return n ;
 }
 
-static int SocketSend(CYASSL* ssl, char *buf, int sz, void *ctx)
+static int SocketSend(WOLFSSL* ssl, char *buf, int sz, void *ctx)
 {
     int n ;
 
@@ -110,7 +111,7 @@
     m_basicAuthUser(NULL), m_basicAuthPassword(NULL), m_httpResponseCode(0)
 {
 
-    /* CyaSSL_Debugging_ON() ; */
+    WOLF_DEBUG_ON ;
 
     ctx = 0 ;
     ssl = 0 ;
@@ -191,7 +192,7 @@
 #define CHECK_CONN_ERR(ret) \
   do{ \
     if(ret) { \
-      cyassl_free() ;\
+      wolfssl_free() ;\
       m_sock.close(); \
       ERR("Connection error (%d)", ret); \
       return HTTP_CONN; \
@@ -200,28 +201,28 @@
 
 #define PRTCL_ERR() \
   do{ \
-    cyassl_free() ;\
+    wolfssl_free() ;\
     m_sock.close(); \
     ERR("Protocol error"); \
     return HTTP_PRTCL; \
   } while(0)
 
-void HTTPClient::cyassl_free(void)
+void HTTPClient::wolfssl_free(void)
 {
     if(ssl) {
-        CyaSSL_free(ssl) ;
+        wolfSSL_free(ssl) ;
         ssl = NULL ;
     }
     if(ctx) {
-        CyaSSL_CTX_free(ctx) ;
+        wolfSSL_CTX_free(ctx) ;
         ctx = NULL ;
     }
-    CyaSSL_Cleanup() ;
+    wolfSSL_Cleanup() ;
 }
 
 HTTPResult HTTPClient::connect(const char* url, HTTP_METH method, IHTTPDataOut* pDataOut, IHTTPDataIn* pDataIn, int timeout) //Execute request
 {
-    CYASSL_METHOD * SSLmethod ;
+    WOLFSSL_METHOD * SSLmethod ;
     m_httpResponseCode = 0; //Invalidate code
     m_timeout = timeout;
     redirect = 0 ;
@@ -233,7 +234,7 @@
 
     char scheme[8];
     char host[32];
-    char path[80];
+    char path[160];
 
     int ret ;
 
@@ -279,41 +280,41 @@
         if(ctx == NULL) {
             switch(SSLver) {
                 case 0 :
-                    SSLmethod = CyaSSLv3_client_method() ;
+                    SSLmethod = wolfSSLv3_client_method() ;
                     break ;
                 case 1 :
-                    SSLmethod = CyaTLSv1_client_method() ;
+                    SSLmethod = wolfTLSv1_client_method() ;
                     break ;
                 case 2 :
-                    SSLmethod = CyaTLSv1_1_client_method() ;
+                    SSLmethod = wolfTLSv1_1_client_method() ;
                     break ;
                 case 3 :
-                    SSLmethod = CyaTLSv1_2_client_method() ;
+                    SSLmethod = wolfTLSv1_2_client_method() ;
                     break ;
             }
-            ctx = CyaSSL_CTX_new((CYASSL_METHOD *)SSLmethod);
+            ctx = wolfSSL_CTX_new((WOLFSSL_METHOD *)SSLmethod);
             if (ctx == NULL) {
                 ERR("unable to get ctx");
                 return HTTP_CONN;
             }
-            CyaSSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, 0);
-            CyaSSL_SetIORecv(ctx, SocketReceive) ;
-            CyaSSL_SetIOSend(ctx, SocketSend) ;
+            wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, 0);
+            wolfSSL_SetIORecv(ctx, SocketReceive) ;
+            wolfSSL_SetIOSend(ctx, SocketSend) ;
         }
         if (ssl == NULL) {
-            ssl = CyaSSL_new(ctx);
+            ssl = wolfSSL_new(ctx);
             if (ssl == NULL) {
                 ERR("unable to get SSL object");
-                cyassl_free() ;
+                wolfssl_free() ;
                 return HTTP_CONN;
             }
         }
 
         DBG("ctx=%x, ssl=%x, ssl->ctx->CBIORecv, CBIOSend=%x, %x\n",
             ctx, ssl, SocketReceive, SocketSend ) ;
-        if (CyaSSL_connect(ssl) != SSL_SUCCESS) {
+        if (wolfSSL_connect(ssl) != SSL_SUCCESS) {
             ERR("SSL_connect failed");
-            cyassl_free() ;
+            wolfssl_free() ;
             return HTTP_CONN;
         }
     } /* SSL connect complete */
@@ -626,7 +627,7 @@
         }
 
     }
-    cyassl_free() ;
+    wolfssl_free() ;
     m_sock.close();
     DBG("Completed HTTP transaction");
     if(redirect)return HTTP_REDIRECT ;
@@ -646,15 +647,15 @@
     int ret;
 
     if(port == HTTPS_PORT) {
-        DBG("Enter CyaSSL_read") ;
+        DBG("Enter wolfSSL_read") ;
 
         m_sock.set_blocking(false, m_timeout);
-        readLen = CyaSSL_read(ssl, buf, maxLen);
+        readLen = wolfSSL_read(ssl, buf, maxLen);
         if (readLen > 0) {
             buf[readLen] = 0;
-            DBG("CyaSSL_read:%s\n", buf);
+            DBG("wolfSSL_read:%s\n", buf);
         } else {
-            ERR("CyaSSL_read, ret = %d", readLen) ;
+            ERR("wolfSSL_read, ret = %d", readLen) ;
             return HTTP_ERROR ;
         }
         DBG("Read %d bytes", readLen);
@@ -747,8 +748,8 @@
     }
 
     if(port == HTTPS_PORT) {
-        DBG("Enter CyaSSL_write") ;
-        if (CyaSSL_write(ssl, buf, len) != len) {
+        DBG("Enter wolfSSL_write") ;
+        if (wolfSSL_write(ssl, buf, len) != len) {
             ERR("SSL_write failed");
             return HTTP_ERROR ;
         }
--- a/HTTPClient.h	Fri Dec 05 07:03:47 2014 +0000
+++ b/HTTPClient.h	Fri Jun 26 00:39:47 2015 +0000
@@ -140,7 +140,7 @@
     HTTPResult send(char* buf, size_t len = 0); //0 on success, err code on failure
     HTTPResult flush(void); //0 on success, err code on failure
     HTTPResult parseURL(const char* url, char* scheme, size_t maxSchemeLen, char* host, size_t maxHostLen, uint16_t* port, char* path, size_t maxPathLen); //Parse URL
-    void cyassl_free(void) ;
+    void wolfssl_free(void) ;
     HTTPResult bAuth(void) ;
     HTTPResult readHeader(void) ;
     
@@ -160,8 +160,8 @@
     /* for CyaSSL */
     int    SSLver ;
     uint16_t port;
-    struct CYASSL_CTX* ctx ;
-    struct CYASSL    * ssl ;
+    struct WOLFSSL_CTX* ctx ;
+    struct WOLFSSL    * ssl ;
 };
 
 //Including data containers here for more convenience