Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
m2mconnectionsecurity.h
00001 /* 00002 * Copyright (c) 2015 ARM Limited. All rights reserved. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * Licensed under the Apache License, Version 2.0 (the License); you may 00005 * not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an AS IS BASIS, WITHOUT 00012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #ifndef __M2M_CONNECTION_SECURITY_H__ 00017 #define __M2M_CONNECTION_SECURITY_H__ 00018 00019 #include "mbed-client/m2mconfig.h" 00020 00021 #include <stdint.h> 00022 00023 class M2MConnectionHandler; 00024 class M2MSecurity; 00025 class M2MConnectionSecurityPimpl; 00026 class M2MConnectionHandler; 00027 00028 /*! \file m2mconnectionsecurity.h 00029 * \brief M2MConnectionSecurity. 00030 * This class provides a method to create a secure socket connection 00031 * to handle connectivity for the mbed Client. It handles sending, receiving 00032 * and establishing a secure connection for mbed Client on top of the 00033 * normal socket connection. 00034 */ 00035 00036 class M2MConnectionSecurity { 00037 public: 00038 typedef enum { 00039 NO_SECURITY = 0, 00040 TLS, 00041 DTLS 00042 } SecurityMode; 00043 00044 private: 00045 // Prevents the use of assignment operator by accident. 00046 M2MConnectionSecurity& operator=( const M2MConnectionSecurity& /*other*/ ); 00047 // Prevents the use of copy constructor by accident. 00048 M2MConnectionSecurity( const M2MConnectionSecurity& /*other*/ ); 00049 00050 public: 00051 /** 00052 * \brief Default Constructor. 00053 */ 00054 M2MConnectionSecurity(SecurityMode mode); 00055 00056 /** 00057 * \brief Default Destructor. 00058 */ 00059 ~M2MConnectionSecurity(); 00060 00061 /** 00062 * \brief Resets the socket connection states. 00063 */ 00064 void reset(); 00065 00066 /** 00067 * \brief Initiatlizes the socket connection states. 00068 */ 00069 int init(const M2MSecurity *security, uint16_t security_instance_id); 00070 00071 /** 00072 * \brief Starts the connection in non-blocking mode. 00073 * \param connHandler The ConnectionHandler object that maintains the socket. 00074 * \return Returns the state of the connection. Successful or not. 00075 */ 00076 int start_connecting_non_blocking(M2MConnectionHandler* connHandler); 00077 00078 /** 00079 * \brief Continues connectivity logic for a secure connection. 00080 * \return Returns an error code if any while continuing the connection sequence. 00081 */ 00082 int continue_connecting(); 00083 00084 /** 00085 * \brief Connects the client to the server. 00086 * \param connHandler The ConnectionHandler object that maintains the socket. 00087 * \return Returns the state of the connection. Successful or not. 00088 */ 00089 int connect(M2MConnectionHandler* connHandler); 00090 00091 /** 00092 * \brief Sends data to the server. 00093 * \param message The data to be sent. 00094 * \param len The length of the data. 00095 * \return Indicates whether the data is sent successfully or not. 00096 */ 00097 int send_message(unsigned char *message, int len); 00098 00099 /** 00100 * \brief Reads the data received from the server. 00101 * \param message The data to be read. 00102 * \param len The length of the data. 00103 * \return Indicates whether the data is read successfully or not. 00104 */ 00105 int read(unsigned char* buffer, uint16_t len); 00106 00107 /** 00108 * \brief Sets the function callback that is called by mbed Client to 00109 * fetch a random number from an application to ensure strong entropy. 00110 * \param random_callback A function pointer that is called by mbed Client 00111 * while performing a secure handshake. 00112 * The function signature should be uint32_t (*random_number_callback)(void); 00113 */ 00114 void set_random_number_callback(random_number_cb callback); 00115 00116 /** 00117 * \brief Sets the function callback that is called by mbed Client to 00118 * provide an entropy source from an application to ensure strong entropy. 00119 * \param entropy_callback A function pointer that is called by mbed-client 00120 * while performing a secure handshake. 00121 * Function signature, if using mbed-client-mbedtls, should be 00122 * int (*mbedtls_entropy_f_source_ptr)(void *data, unsigned char *output, 00123 * size_t len, size_t *olen); 00124 */ 00125 void set_entropy_callback(entropy_cb callback); 00126 00127 /** 00128 * \brief Set socket information for this secure connection. 00129 * \param socket Socket used with this TLS session. 00130 * \param address Pointer to the address of the server. 00131 * \return Indicates whether the data is read successfully or not. 00132 */ 00133 void set_socket(void *socket, void *address); 00134 00135 private: 00136 00137 M2MConnectionSecurityPimpl* _private_impl; 00138 00139 friend class Test_M2MConnectionSecurity; 00140 //friend class Test_M2MConnectionSecurityImpl; 00141 }; 00142 00143 #endif //__M2M_CONNECTION_SECURITY_H__
Generated on Mon Aug 29 2022 19:53:39 by
