This example show how to create a small TLS server using the TLS_cyassl library.

Dependencies:   EthernetInterface8 TLS_cyassl mbed-rtos mbed

Once you launched this program on the mbed, create a small python script :

TLS client

import httplib

conn = httplib.HTTPSConnection("10.2.200.35", 443)
conn.request("GET", "/")
r1 = conn.getresponse()
print r1.status, r1.reason
data = r1.read()
print data

In the terminal, your mbed prints its own IP address. Replace 10.2.200.35 with the IP address of your mbed.

Files at this revision

API Documentation at this revision

Comitter:
feb11
Date:
Wed Sep 18 09:21:51 2013 +0000
Commit message:
initial import

Changed in this revision

EthernetInterface.lib Show annotated file Show diff for this revision Revisions of this file
TLS_cyassl.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetInterface.lib	Wed Sep 18 09:21:51 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/feb11/code/EthernetInterface8/#4166958284dd
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TLS_cyassl.lib	Wed Sep 18 09:21:51 2013 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/feb11/code/TLS_cyassl/#29069dd9abfc
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Sep 18 09:21:51 2013 +0000
@@ -0,0 +1,76 @@
+/** This example shows how to create 
+    a small TLS server using the TLS library.
+*/
+
+#include "mbed.h"
+#include "EthernetInterface.h"
+#include "TLSConnection.h"
+#include "TLSServer.h"
+
+const char host[] = "mbed.org";
+
+const char page[] = " \
+<html>   \
+    <head>\
+        <title>MBED</title>\
+    </head>\
+    <body>\
+    Hello World !\
+    </body>\
+</html>";
+
+int main() 
+{
+    set_time(1379062044 );
+    EthernetInterface eth;
+    if(eth.init() || eth.connect())
+    {
+        printf("Error with EthernetInterface\n\r");
+        return -1;
+    }
+    printf("IP address is %s\n", eth.getIPAddress());
+    
+    TLSServer srv;
+    if(!srv.init())
+    {
+        printf("Failed to intialize server\n");
+        return -1;
+    }
+    
+    TLSConnection con;
+    if(srv.accept(con))
+    {
+        printf("New connection from %s\n", con.get_address());
+        char buffer[512];
+        
+        while(con.is_connected())
+        {
+            int read = con.receive(buffer, 511);
+            if(read == 0)
+            {
+                break;
+            }
+            if(read != -1)
+            {
+                buffer[read] = '\0';
+                printf("%s", buffer);
+                
+                sprintf(buffer, "HTTP/1.0 200 OK\r\nContent-Length: %d", strlen(page));
+                strcat(buffer, "\r\n\r\n");
+                strcat(buffer, page);
+                
+                con.send_all(buffer, strlen(buffer));
+            }
+            else
+            {
+                printf("error occured\n");
+                break;
+            }   
+        }
+        
+        con.close();
+    }
+    eth.disconnect();
+    
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Wed Sep 18 09:21:51 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#ee87e782d34f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Sep 18 09:21:51 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/9c8f0e3462fb
\ No newline at end of file