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.
m2msecurity.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_SECURITY_H 00017 #define M2M_SECURITY_H 00018 00019 #include "mbed-client/m2mobject.h" 00020 00021 // FORWARD DECLARATION 00022 class M2MResource; 00023 00024 /*! \file m2msecurity.h 00025 * \brief M2MSecurity. 00026 * This class represents an interface for the Security Object model of the LWM2M framework. 00027 * It handles the security object instances and all corresponding 00028 * resources. 00029 */ 00030 00031 class M2MSecurity : public M2MObject { 00032 00033 friend class M2MInterfaceFactory; 00034 friend class M2MNsdlInterface; 00035 00036 public: 00037 00038 /** 00039 * \brief An enum defining all resources associated with a 00040 * Security Object in the LWM2M framework. 00041 */ 00042 typedef enum { 00043 M2MServerUri, 00044 BootstrapServer, 00045 SecurityMode, 00046 PublicKey, 00047 ServerPublicKey, 00048 Secretkey, 00049 SMSSecurityMode, 00050 SMSBindingKey, 00051 SMSBindingSecretKey, 00052 M2MServerSMSNumber, 00053 ShortServerID, 00054 ClientHoldOffTime 00055 }SecurityResource; 00056 00057 /** 00058 * \brief An enum defining the type of the security attribute 00059 * used by the Security Object. 00060 */ 00061 typedef enum { 00062 SecurityNotSet = -1, 00063 Psk = 0, 00064 Certificate = 2, 00065 NoSecurity = 3 00066 } SecurityModeType; 00067 00068 /** 00069 * \brief An enum defining an interface operation that can be 00070 * handled by the Security Object. 00071 */ 00072 typedef enum { 00073 Bootstrap = 0x0, 00074 M2MServer = 0x1 00075 } ServerType; 00076 00077 private: 00078 00079 /** 00080 * \brief Constructor 00081 * \param server_type The type of the security object created. Either bootstrap or LWM2M server. 00082 */ 00083 M2MSecurity(ServerType server_type); 00084 00085 // Prevents the use of default constructor. 00086 M2MSecurity(); 00087 00088 // Prevents the use of assignment operator. 00089 M2MSecurity& operator=( const M2MSecurity& /*other*/ ); 00090 00091 // Prevents the use of copy constructor 00092 M2MSecurity( const M2MSecurity& /*other*/ ); 00093 00094 public: 00095 00096 /** 00097 * \brief Destructor 00098 */ 00099 virtual ~M2MSecurity(); 00100 00101 /** 00102 * \brief Creates a new resource for a given resource enum. 00103 * \param rescource With this function, the following resources can be created: 00104 * ' BootstrapServer', 'SecurityMode', 'SMSSecurityMode', 00105 * 'M2MServerSMSNumber', 'ShortServerID', 'ClientHoldOffTime'. 00106 * \param value The value to be set on the resource, in integer format. 00107 * \return M2MResource if created successfully, else NULL. 00108 */ 00109 M2MResource* create_resource(SecurityResource rescource, uint32_t value); 00110 00111 /** 00112 * \brief Deletes a resource with a given resource enum. 00113 * Mandatory resources cannot be deleted. 00114 * \param resource The resource to be deleted. 00115 * \return True if deleted, else false. 00116 */ 00117 bool delete_resource(SecurityResource rescource); 00118 00119 /** 00120 * \brief Sets the value of a given resource enum. 00121 * \param resource With this function, a value can be set for the following resources: 00122 * 'M2MServerUri', 'SMSBindingKey', 'SMSBindingSecretKey'. 00123 * \param value The value to be set on the resource, in string format. 00124 * \return True if successfully set, else false. 00125 */ 00126 bool set_resource_value(SecurityResource resource, 00127 const String &value); 00128 00129 /** 00130 * \brief Sets the value of a given resource enum. 00131 * \param resource With this function, a value can be set for the following resourecs: 00132 * 'BootstrapServer', 'SecurityMode', 'SMSSecurityMode', 00133 * 'M2MServerSMSNumber', 'ShortServerID', 'ClientHoldOffTime'. 00134 * \param value The value to be set on the resource, in integer format. 00135 * \return True if successfully set, else false. 00136 */ 00137 bool set_resource_value(SecurityResource resource, 00138 uint32_t value); 00139 00140 /** 00141 * \brief Sets the value of a given resource enum. 00142 * \param resource With this function, a value can be set for the follwing resources: 00143 * 'PublicKey', 'ServerPublicKey', 'Secretkey'. 00144 * \param value The value to be set on the resource, in uint8_t format. 00145 * \param size The size of the buffer value to be set on the resource. 00146 * \return True if successfully set, else false. 00147 */ 00148 bool set_resource_value(SecurityResource resource, 00149 const uint8_t *value, 00150 const uint16_t length); 00151 00152 /** 00153 * \brief Returns the value of a given resource enum, in string format. 00154 * \param resource With this function, the following resources can return a value: 00155 * 'M2MServerUri','SMSBindingKey', 'SMSBindingSecretKey'. 00156 * \return The value associated with the resource. If the resource is not valid an empty string is returned. 00157 */ 00158 String resource_value_string(SecurityResource resource) const; 00159 00160 /** 00161 * \brief Populates the data buffer and returns the size of the buffer. 00162 * \param resource With this function, the following resources can return a value: 00163 * 'PublicKey', 'ServerPublicKey', 'Secretkey'. 00164 * \param [OUT]data A copy of the data buffer that contains the value. The caller 00165 * is responsible for freeing this buffer. 00166 * \return The size of the populated buffer. 00167 */ 00168 uint32_t resource_value_buffer(SecurityResource resource, 00169 uint8_t *&data) const; 00170 00171 /** 00172 * \brief Returns a pointer to the value and size of the buffer. 00173 * \param resource With this function, the following resources can return a value: 00174 * 'PublicKey', 'ServerPublicKey', 'Secretkey'. 00175 * \param [OUT]data A pointer to the data buffer that contains the value. 00176 * \return The size of the populated buffer. 00177 */ 00178 uint32_t resource_value_buffer(SecurityResource resource, 00179 const uint8_t *&data) const; 00180 00181 /** 00182 * \brief Returns the value of a given resource name, in integer format. 00183 * \param resource With this function, the following resources can return a value: 00184 * 'BootstrapServer', 'SecurityMode', 'SMSSecurityMode', 00185 * 'M2MServerSMSNumber', 'ShortServerID', 'ClientHoldOffTime'. 00186 * \return The value associated with the resource. If the resource is not valid 0 is returned. 00187 */ 00188 uint32_t resource_value_int(SecurityResource resource) const; 00189 00190 00191 /** 00192 * \brief Returns whether a resource instance with a given resource enum exists or not 00193 * \param resource Resource enum. 00194 * \return True if at least one instance exists, else false. 00195 */ 00196 bool is_resource_present(SecurityResource resource)const; 00197 00198 /** 00199 * \brief Returns the total number of resources for a security object. 00200 * \return The total number of resources. 00201 */ 00202 uint16_t total_resource_count()const; 00203 00204 /** 00205 * \brief Returns the type of the Security Object. It can be either 00206 * Bootstrap or M2MServer. 00207 * \return ServerType The type of the Security Object. 00208 */ 00209 ServerType server_type() const; 00210 00211 private: 00212 00213 M2MResource* get_resource(SecurityResource resource) const; 00214 void clear_resources(); 00215 00216 private: 00217 00218 M2MObjectInstance* _server_instance; 00219 ServerType _server_type; 00220 00221 friend class Test_M2MSecurity; 00222 friend class Test_M2MInterfaceImpl; 00223 friend class Test_M2MConnectionSecurityImpl; 00224 friend class Test_M2MConnectionHandlerPimpl_linux; 00225 friend class Test_M2MConnectionHandlerPimpl_mbed; 00226 friend class Test_M2MConnectionSecurityPimpl; 00227 friend class Test_M2MNsdlInterface; 00228 friend class Test_M2MConnectionHandlerPimpl_classic; 00229 }; 00230 00231 #endif // M2M_SECURITY_H 00232 00233
Generated on Tue Jul 12 2022 21:20:28 by
1.7.2