Mistake on this page? Email us
m2msecurity.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 ARM Limited. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  * Licensed under the Apache License, Version 2.0 (the License); you may
5  * not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef M2M_SECURITY_H
17 #define M2M_SECURITY_H
18 
19 #include "mbed-client/m2mobject.h"
20 
23 // FORWARD DECLARATION
24 class M2MResource;
25 
26 
31 class M2MSecurity : public M2MObject {
32 
33 friend class M2MInterfaceFactory;
34 friend class M2MNsdlInterface;
35 
36 public:
37 
42  typedef enum {
43  M2MServerUri,
44  BootstrapServer,
45  SecurityMode,
46  PublicKey,
47  ServerPublicKey,
48  Secretkey,
49  SMSSecurityMode,
50  SMSBindingKey,
51  SMSBindingSecretKey,
52  M2MServerSMSNumber,
53  ShortServerID,
54  ClientHoldOffTime,
55  OpenCertificateChain,
56  CloseCertificateChain,
57  ReadDeviceCertificateChain
59 
64  typedef enum {
65  SecurityNotSet = -1,
66  Psk = 0,
67  Certificate = 2,
68  NoSecurity = 3,
69  EST = 4
71 
76  typedef enum {
77  M2MServer = 0x0,
78  Bootstrap = 0x1,
79  NotDefined =0x2
80  } ServerType;
81 
82 private:
83 
89 
90 
94  virtual ~M2MSecurity();
95 
96  // Prevents the use of default constructor.
97  M2MSecurity();
98 
99  // Prevents the use of assignment operator.
100  M2MSecurity& operator=( const M2MSecurity& /*other*/ );
101 
102  // Prevents the use of copy constructor
103  M2MSecurity( const M2MSecurity& /*other*/ );
104 
105 public:
106 
110  static M2MSecurity* get_instance();
111 
115  static void delete_instance();
116 
123 
130 
135 
145  M2MResource* create_resource(SecurityResource rescource, uint32_t value, uint16_t instance_id);
146 
154  bool delete_resource(SecurityResource rescource, uint16_t instance_id);
155 
164  bool set_resource_value(SecurityResource resource,
165  const String &value,
166  uint16_t instance_id);
167 
177  bool set_resource_value(SecurityResource resource,
178  uint32_t value,
179  uint16_t instance_id);
180 
190  bool set_resource_value(SecurityResource resource,
191  const uint8_t *value,
192  const uint16_t length,
193  uint16_t instance_id);
194 
202  String resource_value_string(SecurityResource resource, uint16_t instance_id) const;
203 
215  int resource_value_buffer(SecurityResource resource,
216  uint8_t *&data,
217  uint16_t instance_id,
218  size_t *buffer_len) const;
219 
228  uint32_t resource_value_buffer(SecurityResource resource,
229  const uint8_t *&data,
230  uint16_t instance_id) const;
231 
240  int resource_value_buffer_size(SecurityResource resource,
241  uint16_t instance_id,
242  size_t *buffer_len) const;
243 
252  uint32_t resource_value_int(SecurityResource resource,
253  uint16_t instance_id) const;
254 
261  bool is_resource_present(SecurityResource resource,
262  uint16_t instance_id) const;
263 
269  uint16_t total_resource_count(uint16_t instance_id) const;
270 
277  ServerType server_type(uint16_t instance_id) const;
278 
284  int32_t get_security_instance_id(ServerType server_type) const;
285 
286  M2MResource* get_resource(SecurityResource resource, uint16_t instance_id = 0) const;
287 private:
288 
289 
290  void clear_resources();
291  void clear_resources(uint16_t instance_id);
292  void create_resources(M2MObjectInstance *server_instance,
293  M2MSecurity::ServerType server_type);
294 
295 protected:
296  static M2MSecurity* _instance;
297 
298  friend class Test_M2MSecurity;
299  friend class Test_M2MInterfaceImpl;
300  friend class Test_M2MConnectionSecurityImpl;
301  friend class Test_M2MConnectionHandlerPimpl_linux;
302  friend class Test_M2MConnectionHandlerPimpl_mbed;
303  friend class Test_M2MConnectionSecurityPimpl;
304  friend class Test_M2MNsdlInterface;
305  friend class Test_M2MConnectionHandlerPimpl_classic;
306 };
307 
308 #endif // M2M_SECURITY_H
309 
310 
Definition: m2mobject.h:35
Definition: m2mserver.h:31
String resource_value_string(SecurityResource resource, uint16_t instance_id) const
Returns the value of a given resource enum, in string format.
ServerType
An enum defining an interface operation that can be handled by the Security Object.
Definition: m2msecurity.h:76
uint32_t resource_value_int(SecurityResource resource, uint16_t instance_id) const
Returns the value of a given resource name, in integer format.
header M2MObject
bool is_resource_present(SecurityResource resource, uint16_t instance_id) const
Returns whether a resource instance with a given resource enum exists or not.
SecurityResource
An enum defining all resources associated with a Security Object in the LWM2M framework.
Definition: m2msecurity.h:42
static M2MSecurity * get_instance()
Get the singleton instance of M2MSecurity.
Definition: m2mobjectinstance.h:42
bool set_resource_value(SecurityResource resource, const String &value, uint16_t instance_id)
Sets the value of a given resource enum.
Definition: m2msecurity.h:31
M2MObjectInstance * create_object_instance(ServerType server_type)
Creates a new object instance.
bool delete_resource(SecurityResource rescource, uint16_t instance_id)
Deletes a resource with a given resource enum. Mandatory resources cannot be deleted.
static void delete_instance()
Delete the singleton instance of M2MSecurity.
void remove_security_instances()
Remove all security object instances.
uint16_t total_resource_count(uint16_t instance_id) const
Returns the total number of resources for a security object.
int32_t get_security_instance_id(ServerType server_type) const
Returns first bootstrap or lwm2m server security object instance id.
int resource_value_buffer(SecurityResource resource, uint8_t *&data, uint16_t instance_id, size_t *buffer_len) const
Populates the data buffer and returns the size of the buffer.
ServerType server_type(uint16_t instance_id) const
Returns the type of the Security Object. It can be either Bootstrap or M2MServer. ...
Definition: m2mresource.h:38
SecurityModeType
An enum defining the type of the security attribute used by the Security Object.
Definition: m2msecurity.h:64
Definition: m2minterfacefactory.h:36
M2MResource * create_resource(SecurityResource rescource, uint32_t value, uint16_t instance_id)
Creates a new resource for a given resource enum.
uint16_t instance_id() const
Returns the object's instance ID.
int resource_value_buffer_size(SecurityResource resource, uint16_t instance_id, size_t *buffer_len) const
Get a size of the buffer.