MAXREFDES143#: DeepCover Embedded Security in IoT Authenticated Sensing & Notification

Dependencies:   MaximInterface mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers WebServerInterface.hpp Source File

WebServerInterface.hpp

00001 /*******************************************************************************
00002 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
00003 *
00004 * Permission is hereby granted, free of charge, to any person obtaining a
00005 * copy of this software and associated documentation files (the "Software"),
00006 * to deal in the Software without restriction, including without limitation
00007 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00008 * and/or sell copies of the Software, and to permit persons to whom the
00009 * Software is furnished to do so, subject to the following conditions:
00010 *
00011 * The above copyright notice and this permission notice shall be included
00012 * in all copies or substantial portions of the Software.
00013 *
00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00015 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00016 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00017 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
00018 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00019 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00020 * OTHER DEALINGS IN THE SOFTWARE.
00021 *
00022 * Except as contained in this notice, the name of Maxim Integrated
00023 * Products, Inc. shall not be used except as stated in the Maxim Integrated
00024 * Products, Inc. Branding Policy.
00025 *
00026 * The mere transfer of this software does not imply any licenses
00027 * of trade secrets, proprietary technology, copyrights, patents,
00028 * trademarks, maskwork rights, or any other form of intellectual
00029 * property whatsoever. Maxim Integrated Products, Inc. retains all
00030 * ownership rights.
00031 *******************************************************************************/
00032 
00033 #ifndef WEBSERVERINTERFACE_HPP
00034 #define WEBSERVERINTERFACE_HPP
00035 
00036 #include <string>
00037 #include <MaximInterface/Utilities/RomId.hpp>
00038 
00039 /// The message type described by the POST.
00040 enum PostEvent {
00041   SensorDataEvent,   ///< Adding sensor data to the log.
00042   InvalidSensorEvent ///< Reporting an invalid sensor node.
00043 };
00044 
00045 namespace mbed { class Serial; }
00046 namespace MaximInterface { class DS2465; }
00047 class ESP8266;
00048 struct SensorData;
00049 
00050 /// Network interface to the web server supporting authenticated posting of event
00051 /// through an HTTP challenge-respones scheme with SHA-256 data signing.
00052 class WebServerInterface {
00053 public:
00054   /// @param esp8266 Interface to ESP8266 for Wi-Fi access.
00055   /// @param pc Optional serial interface for received web traffic.
00056   WebServerInterface (ESP8266 & esp8266) : esp8266(esp8266) {}
00057 
00058   /// Initialize network interface and connect to access point.
00059   /// @returns True on success.
00060   bool initialize();
00061 
00062   /// Send an authenticated event message to the web server.
00063   /// @param macCoProc
00064   /// Coprocessor such as the DS2465 used to calculate the authentication MAC.
00065   /// @param event Event message type.
00066   /// @postData Message body as determined by the event message type.
00067   /// @setSecret True if the Transport Secret needs to be selected in the coprocessor.
00068   /// @returns True on success.
00069   bool authPostHttpEvent(MaximInterface::DS2465 & macCoproc, PostEvent event,
00070                          const std::string & postData, bool setSecret);
00071 
00072   /// Format sensor data as text suitable for use in a POST body.
00073   /// @param sensorData Sensor data to format.
00074   /// @returns Data formatted for web server.
00075   static std::string formatSensorDataPostBody(const SensorData & sensorData);
00076 
00077   /// @{
00078   /// Session ID used by the web server to distinguish between multiple Controllers.
00079   const MaximInterface::RomId & sessionId () const { return m_sessionId; }
00080   const std::string & sessionIdString() const { return m_sessionIdString; }
00081   void setSessionId(const MaximInterface::RomId & sessionId );
00082   /// @}
00083 
00084 private:
00085   /// @{
00086   /// Configuration strings.
00087   static const char wifiSsid[];
00088   static const char wifiPassword[];
00089   static const char serverAddress[];
00090   static const unsigned int serverPort;
00091   static const char serverPostPath[];
00092   static const char serverChallengePath[];
00093   /// @}
00094 
00095   MaximInterface::RomId m_sessionId;
00096   std::string m_sessionIdString;
00097 
00098   ESP8266 & esp8266;
00099 };
00100 
00101 #endif