Contiki-NG
lwm2m-security.h
1/*
2 * Copyright (c) 2017, SICS Swedish ICT
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the copyright holder nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28 * OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31/**
32 * \addtogroup lwm2m
33 * @{
34 *
35 */
36#ifndef LWM2M_SECURITY_H
37#define LWM2M_SECURITY_H
38
39#define LWM2M_SECURITY_SERVER_URI_ID 0
40#define LWM2M_SECURITY_BOOTSTRAP_SERVER_ID 1
41#define LWM2M_SECURITY_MODE_ID 2
42#define LWM2M_SECURITY_CLIENT_PKI_ID 3
43#define LWM2M_SECURITY_SERVER_PKI_ID 4
44#define LWM2M_SECURITY_KEY_ID 5
45#define LWM2M_SECURITY_SHORT_SERVER_ID 10
46
47/* Pre-shared key mode */
48#define LWM2M_SECURITY_MODE_PSK 0
49/* Raw Public Key mode */
50#define LWM2M_SECURITY_MODE_RPK 1
51/* Certificate mode */
52#define LWM2M_SECURITY_MODE_CERTIFICATE 2
53/* NoSec mode */
54#define LWM2M_SECURITY_MODE_NOSEC 3
55
56#ifdef LWM2M_SECURITY_CONF_URI_SIZE
57#define LWM2M_SECURITY_URI_SIZE LWM2M_SECURITY_CONF_URI_SIZE
58#else /* LWM2M_SECURITY_CONF_URI_SIZE */
59#define LWM2M_SECURITY_URI_SIZE 64
60#endif /* LWM2M_SECURITY_CONF_URI_SIZE */
61
62#ifdef LWM2M_SECURITY_CONF_KEY_SIZE
63#define LWM2M_SECURITY_KEY_SIZE LWM2M_SECURITY_CONF_KEY_SIZE
64#else /* LWM2M_SECURITY_CONF_KEY_SIZE */
65#define LWM2M_SECURITY_KEY_SIZE 32
66#endif /* LWM2M_SECURITY_CONF_KEY_SIZE */
67
68typedef struct {
69 lwm2m_object_instance_t instance;
70 uint16_t server_id;
71 uint8_t bootstrap;
72 uint8_t security_mode;
73 uint8_t server_uri[LWM2M_SECURITY_URI_SIZE];
74 uint8_t server_uri_len;
75 uint8_t public_key[LWM2M_SECURITY_KEY_SIZE];
76 uint8_t public_key_len;
77 uint8_t secret_key[LWM2M_SECURITY_KEY_SIZE];
78 uint8_t secret_key_len;
79 uint8_t server_public_key[LWM2M_SECURITY_KEY_SIZE];
80 uint8_t server_public_key_len;
81} lwm2m_security_server_t;
82
83lwm2m_security_server_t *lwm2m_security_get_first(void);
84lwm2m_security_server_t *lwm2m_security_get_next(lwm2m_security_server_t *last);
85
86lwm2m_security_server_t *lwm2m_security_add_server(uint16_t instance_id,
87 uint16_t server_id,
88 const uint8_t *server_uri,
89 uint8_t server_uri_len);
90
91int lwm2m_security_set_server_psk(lwm2m_security_server_t *server,
92 const uint8_t *identity,
93 uint8_t identity_len,
94 const uint8_t *key,
95 uint8_t key_len);
96
97void lwm2m_security_init(void);
98
99#endif /* LWM2M_SECURITY_H */
100/** @} */