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 class M2MConnectionHandler; 00021 class M2MSecurity; 00022 class M2MConnectionSecurityPimpl; 00023 00024 /** 00025 * \brief M2MConnectionSecurity. 00026 * This class provides a method to create a secure socket connection 00027 * to handle connectivity for the mbed Client. It will handle sending, receiving 00028 * and establishing a secure connection for mbed Client on top of the 00029 * normal socket connection. 00030 */ 00031 00032 class M2MConnectionSecurity { 00033 public: 00034 typedef enum { 00035 NO_SECURITY = 0, 00036 TLS, 00037 DTLS 00038 } SecurityMode; 00039 00040 private: 00041 // Prevents the use of assignment operator by accident. 00042 M2MConnectionSecurity& operator=( const M2MConnectionSecurity& /*other*/ ); 00043 // Prevents the use of copy constructor by accident. 00044 M2MConnectionSecurity( const M2MConnectionSecurity& /*other*/ ); 00045 00046 public: 00047 /** 00048 * \brief Default Constructor. 00049 */ 00050 M2MConnectionSecurity(SecurityMode mode); 00051 00052 /** 00053 * \brief Default Destructor. 00054 */ 00055 ~M2MConnectionSecurity(); 00056 00057 /** 00058 * \brief Resets the socket connection states. 00059 */ 00060 void reset(); 00061 00062 /** 00063 * \brief Initiatlizes the socket connection states. 00064 */ 00065 int init(const M2MSecurity *security); 00066 00067 /** 00068 * \brief Starts the connection in non-blocking mode. 00069 * \param connHandler The ConnectionHandler object that maintains the socket. 00070 * \return Returns the state of the connection. Successful or not. 00071 */ 00072 int start_connecting_non_blocking(M2MConnectionHandler* connHandler); 00073 00074 /** 00075 * \brief Continues connectivity logic for secure connection. 00076 * \return Returns an error code if any while continuing the connection sequence. 00077 */ 00078 int continue_connecting(); 00079 00080 /** 00081 * \brief Connects the client to the server. 00082 * \param connHandler The ConnectionHandler object that maintains the socket. 00083 * \return Returns the state of the connection. Successful or not. 00084 */ 00085 int connect(M2MConnectionHandler* connHandler); 00086 00087 /** 00088 * \brief Sends data to the server. 00089 * \param message The data to be sent. 00090 * \param len The length of the data. 00091 * \return Indicates whether the data is sent successfully or not. 00092 */ 00093 int send_message(unsigned char *message, int len); 00094 00095 /** 00096 * \brief Reads the data received from the server. 00097 * \param message The data to be read. 00098 * \param len The length of the data. 00099 * \return Indicates whether the data is read successfully or not. 00100 */ 00101 int read(unsigned char* buffer, uint16_t len); 00102 00103 /** 00104 * \brief Sets the function callback that is called by mbed-client to 00105 * fetch a random number from an application to ensure strong entropy. 00106 * \param random_callback A function pointer that is called by mbed-client 00107 * while performing a secure handshake. 00108 * The function signature should be uint32_t (*random_number_callback)(void); 00109 */ 00110 void set_random_number_callback(random_number_cb callback); 00111 00112 /** 00113 * \brief Sets the function callback that is called by mbed-client to 00114 * provide an entropy source from an application to ensure strong entropy. 00115 * \param entropy_callback A function pointer that is called by mbed-client 00116 * while performing a secure handshake. 00117 * Function signature, if using mbed-client-mbedtls, should be 00118 * int (*mbedtls_entropy_f_source_ptr)(void *data, unsigned char *output, 00119 * size_t len, size_t *olen); 00120 */ 00121 void set_entropy_callback(entropy_cb callback); 00122 00123 private: 00124 00125 M2MConnectionSecurityPimpl* _private_impl; 00126 00127 friend class Test_M2MConnectionSecurity; 00128 //friend class Test_M2MConnectionSecurityImpl; 00129 }; 00130 00131 #endif //__M2M_CONNECTION_SECURITY_H__
Generated on Tue Jul 12 2022 13:05:06 by
1.7.2