fork of wolfSSL/MQTTS library with increased message buffer & increased number of subscribed topics

Dependencies:   FP MQTTPacket

Fork of MQTTS by wolf SSL

Revision:
46:d8968fcc21b8
Parent:
45:6c023c2ab095
--- a/MQTTSocket.h	Sun Jul 26 06:10:10 2015 +0000
+++ b/MQTTSocket.h	Sun Jul 26 09:50:40 2015 +0000
@@ -4,7 +4,7 @@
 #include "MQTTmbed.h"
 #include "TCPSocketConnection.h"
 #include "wolfssl/ssl.h"
-#include    <wolfssl/wolfcrypt/error-crypt.h>
+#include "wolfssl/wolfcrypt/error-crypt.h"
 
 static int SocketReceive(WOLFSSL* ssl, char *buf, int sz, void *sock)
 {
@@ -19,14 +19,14 @@
 class MQTTSocket
 {
 public:
-    int connect(char* hostname, int port,  bool tls = false, int timeout=1000)
+    int connect(char* hostname, int port,  const char *certName = NULL, int timeout=1000)
     {
 
         mysock.set_blocking(false, timeout);    // 1 second Timeout
-        isTLS = tls ;
+        isTLS = certName == NULL ? false : true ;
         int ret = mysock.connect(hostname, port);
         if((ret == 0) && isTLS) {
-            return tls_connect(&mysock) ;
+            return tls_connect(&mysock, certName) ;
         } else return ret ;
     }
     
@@ -55,23 +55,28 @@
         }
         return mysock.close();
     }
-    
+
 private:
 
     TCPSocketConnection mysock;
     bool  isTLS ;
     WOLFSSL_CTX* ctx;
     WOLFSSL*     ssl;
-
-    int tls_connect(TCPSocketConnection *sock)
+    
+    int tls_connect(TCPSocketConnection *sock, const char *certName)
     {
         /* create and initiLize WOLFSSL_CTX structure */
         if ((ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method())) == NULL) {
             printf("SSL_CTX_new error.\n");
             return EXIT_FAILURE;
         }
-
-        wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, 0);
+        if(*certName == '\0'){
+            wolfSSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, 0);
+        } else {
+            if (wolfSSL_CTX_load_verify_locations(ctx, certName,0) != SSL_SUCCESS)
+                printf("can't load ca file\n");
+        }
+        
         wolfSSL_SetIORecv(ctx, SocketReceive) ;
         wolfSSL_SetIOSend(ctx, SocketSend) ;