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 
21 // FORWARD DECLARATION
22 class M2MResource;
23 
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  } ServerType;
80 
81 private:
82 
88 
89 
93  virtual ~M2MSecurity();
94 
95  // Prevents the use of default constructor.
96  M2MSecurity();
97 
98  // Prevents the use of assignment operator.
99  M2MSecurity& operator=( const M2MSecurity& /*other*/ );
100 
101  // Prevents the use of copy constructor
102  M2MSecurity( const M2MSecurity& /*other*/ );
103 
104 public:
105 
109  static M2MSecurity* get_instance();
110 
114  static void delete_instance();
115 
122 
127 
137  M2MResource* create_resource(SecurityResource rescource, uint32_t value, uint16_t instance_id);
138 
146  bool delete_resource(SecurityResource rescource, uint16_t instance_id);
147 
156  bool set_resource_value(SecurityResource resource,
157  const String &value,
158  uint16_t instance_id);
159 
169  bool set_resource_value(SecurityResource resource,
170  uint32_t value,
171  uint16_t instance_id);
172 
182  bool set_resource_value(SecurityResource resource,
183  const uint8_t *value,
184  const uint16_t length,
185  uint16_t instance_id);
186 
194  String resource_value_string(SecurityResource resource, uint16_t instance_id) const;
195 
207  int resource_value_buffer(SecurityResource resource,
208  uint8_t *&data,
209  uint16_t instance_id,
210  size_t *buffer_len) const;
211 
220  uint32_t resource_value_buffer(SecurityResource resource,
221  const uint8_t *&data,
222  uint16_t instance_id) const;
223 
232  int resource_value_buffer_size(SecurityResource resource,
233  uint16_t instance_id,
234  size_t *buffer_len) const;
235 
244  uint32_t resource_value_int(SecurityResource resource,
245  uint16_t instance_id) const;
246 
253  bool is_resource_present(SecurityResource resource,
254  uint16_t instance_id) const;
255 
261  uint16_t total_resource_count(uint16_t instance_id) const;
262 
269  ServerType server_type(uint16_t instance_id) const;
270 
276  int32_t get_security_instance_id(ServerType server_type) const;
277 
278  M2MResource* get_resource(SecurityResource resource, uint16_t instance_id = 0) const;
279 private:
280 
281 
282  void clear_resources(uint16_t instance_id = 0);
283 
284 protected:
285  static M2MSecurity* _instance;
286 
287  friend class Test_M2MSecurity;
288  friend class Test_M2MInterfaceImpl;
289  friend class Test_M2MConnectionSecurityImpl;
290  friend class Test_M2MConnectionHandlerPimpl_linux;
291  friend class Test_M2MConnectionHandlerPimpl_mbed;
292  friend class Test_M2MConnectionSecurityPimpl;
293  friend class Test_M2MNsdlInterface;
294  friend class Test_M2MConnectionHandlerPimpl_classic;
295 };
296 
297 #endif // M2M_SECURITY_H
298 
299 
The base class for Client Objects.
Definition: m2mobject.h:39
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.
M2MObject. This class is the base class for the mbed Client Objects.
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:36
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.
Definition: m2mstring.h:33
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. ...
The base class for Client Resources.
Definition: m2mresource.h:40
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.