Establishing a connection to mbed.org using TLS
Dependencies: EthernetInterface5 TLS_axTLS mbed-rtos mbed
Revision 0:e98faa82e3ee, committed 2013-09-12
- Comitter:
- feb11
- Date:
- Thu Sep 12 15:20:12 2013 +0000
- Commit message:
- initial import
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EthernetInterface.lib Thu Sep 12 15:20:12 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/feb11/code/EthernetInterface5/#f50f7ba19f50
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TLS_axTLS.lib Thu Sep 12 15:20:12 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/feb11/code/TLS_axTLS/#85fceccc1a7c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Thu Sep 12 15:20:12 2013 +0000
@@ -0,0 +1,76 @@
+/*
+ This example shows how to use TLS library. It
+ establishes a connection to mbed.org and then
+ closes this connection immediately.
+
+ Don't forget to copy certificates on your
+ mbed before running this program. You can
+ download them as a zip package from the wiki:
+ http://mbed.org/users/feb11/code/TLSExample/
+*/
+
+
+
+#include "mbed.h"
+#include "EthernetInterface.h"
+#include "CertificateManager.h"
+#include "TLSConnection.h"
+
+const char host[] = "mbed.org";
+LocalFileSystem local("local");
+
+int main()
+{
+ /*
+ Ensure that the mbed has a time value
+ approximately equal to the correct timestamp.
+ This is needed because the certificate manager
+ uses the timestamp to check whether certificates
+ expired.
+
+ Don't hesitate to remove this line if your mbed
+ already store a correct time value, or update
+ this value.
+ */
+ set_time(1378376823);
+
+ /* Starting Ethernet */
+ EthernetInterface eth;
+ if(eth.init() || eth.connect()) {
+ printf("Error with EthernetInterface\n\r");
+ return -1;
+ }
+
+ /*
+ Loading certificates in precomputed mode.
+ Notice that cert4 is the root certificate.
+ */
+ CertificateManager::add("/local/cert1.der");
+ CertificateManager::add("/local/cert2.der");
+ CertificateManager::add("/local/cert3.der");
+ CertificateManager::add("/local/cert4.der");
+ if(!CertificateManager::load(true)) {
+ printf("Failed to load certificates\n");
+ return -1;
+ }
+
+ /* Starting connection to mbed.org */
+ TLSConnection con;
+ if(con.connect(host)) {
+ printf("Connected to %s !\n", host);
+
+ /*
+ Since no memory is needed once the connection
+ is established, we don't need to call
+ CertificateManager::clear() to free memory.
+ */
+ con.close();
+ } else {
+ printf("Failed to connect to %s\n", host);
+ }
+
+ eth.disconnect();
+
+ return 0;
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Thu Sep 12 15:20:12 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 Thu Sep 12 15:20:12 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/9c8f0e3462fb \ No newline at end of file