Timothy Beight / Mbed 2 deprecated 6_songs-from-the-cloud

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Fork of 6_songs-from-the-cloud by MakingMusicWorkshop

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers m2msecurity.h Source File

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 /**
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 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 Enum defining the type of a 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 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, 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 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, 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 the resource with the given resource enum.
00113      * Mandatory resources cannot be deleted.
00114      * @param resource, 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 the 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, 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 the 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, 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 the 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, Value to be set on the resource, in uint8_t format.
00145      * @param size, 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 the given resource enum, in String.
00154      * @param resource, With this function, the following resources can return a value:
00155      * 'M2MServerUri','SMSBindingKey', 'SMSBindingSecretKey'.
00156      * @return Value associated with that 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 fucntion, the following resources can return a value:
00163      * 'PublicKey', 'ServerPublicKey', 'Secretkey'.
00164      * @param [OUT] data, Data buffer that contains the value.
00165      * @return Size of the populated buffer.
00166      */
00167     uint32_t resource_value_buffer(SecurityResource resource,
00168                                    uint8_t *&data) const;
00169 
00170     /**
00171      * @brief Returns the value of the given resource name, in Integer.
00172      * @param resource, With this function, the following resources can return a value:
00173      * 'BootstrapServer', 'SecurityMode', 'SMSSecurityMode',
00174      * 'M2MServerSMSNumber', 'ShortServerID', 'ClientHoldOffTime'.
00175      * @return Value associated with the resource. If the resource is not valid 0 is returned.
00176      */
00177     uint32_t resource_value_int(SecurityResource resource) const;
00178 
00179 
00180     /**
00181      * @brief Returns whether the resource instance with given resource enum exists or not
00182      * @param resource, Resource enum.
00183      * @return True if at least one instance exists, else false.
00184      */
00185     bool is_resource_present(SecurityResource resource)const;
00186 
00187     /**
00188      * @brief Returns the total number of resources for a security object.
00189      * @return Total number of resources.
00190      */
00191     uint16_t total_resource_count()const;
00192 
00193     /**
00194      * @brief Returns the type of the Security Object. It can be either
00195      * Bootstrap or M2MServer.
00196      * @return ServerType, Type of the Security Object.
00197      */
00198     ServerType server_type() const;
00199 
00200 private:
00201 
00202     M2MResource* get_resource(SecurityResource resource) const;
00203 
00204 private:
00205 
00206     ServerType            _server_type;
00207     M2MObjectInstance*    _server_instance;
00208 
00209     friend class Test_M2MSecurity;
00210     friend class Test_M2MInterfaceImpl;
00211     friend class Test_M2MConnectionSecurityImpl;
00212     friend class Test_M2MConnectionHandlerPimpl_linux;
00213     friend class Test_M2MConnectionHandlerPimpl_mbed;
00214     friend class Test_M2MConnectionSecurityPimpl;
00215 };
00216 
00217 #endif // M2M_SECURITY_H
00218 
00219