KNX IoT
KNX IoT Point API stack implementation
oc_knx_sec.h
Go to the documentation of this file.
1 /*
2 // Copyright (c) 2021-2023 Cascoda Ltd
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may 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,
12 // WITHOUT 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 */
21 #ifndef OC_KNX_SEC_INTERNAL_H
22 #define OC_KNX_SEC_INTERNAL_H
23 
24 #include <stddef.h>
25 
26 #include "oc_ri.h"
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
36 typedef enum {
41  254,
44 
52 
60 
131 typedef struct oc_auth_at_t
132 {
133  oc_string_t id;
137  oc_string_t aud;
138  oc_string_t sub;
139  oc_string_t kid;
140  oc_string_t osc_version;
141  oc_string_t osc_ms;
142  uint8_t osc_hkdf;
144  uint8_t osc_alg;
146  oc_string_t
148  oc_string_t osc_contextid;
151  oc_string_t osc_id;
153  oc_string_t
155  int nbf;
156  int ga_len;
157  int64_t *ga;
160 
167 
178 int oc_core_set_at_table(size_t device_index, int index, oc_auth_at_t entry,
179  bool store);
180 
190  char *context_id);
191 
201 int oc_core_find_at_entry_with_osc_id(size_t device_index, uint8_t *osc_id,
202  size_t osc_id_len);
203 
211 int oc_core_find_at_entry_empty_slot(size_t device_index);
212 
228 void oc_oscore_set_auth_mac(char *client_senderid, int client_senderid_size,
229  char *clientrecipient_id,
230  int clientrecipient_id_size, uint8_t *shared_key,
231  int shared_key_size);
232 
247 void oc_oscore_set_auth_device(char *client_senderid, int client_senderid_size,
248  char *clientrecipient_id,
249  int clientrecipient_id_size, uint8_t *shared_key,
250  int shared_key_size);
251 
259 oc_auth_at_t *oc_get_auth_at_entry(size_t device_index, int index);
260 
267 void oc_print_auth_at_entry(size_t device_index, int index);
268 
275 void oc_delete_at_table(size_t device_index);
276 
286 void oc_reset_at_table(size_t device_index, int erase_code);
287 
295 int oc_at_delete_entry(size_t device_index, int index);
296 
303 
310 
325 void oc_create_knx_sec_resources(size_t device);
326 
333 void oc_init_oscore(size_t device_index);
334 
341 void oc_init_oscore_from_storage(size_t device_index, bool from_storage);
342 
353  oc_interface_mask_t resource_interface);
354 
364  oc_method_t method);
365 
375 bool oc_knx_sec_check_acl(oc_method_t method, const oc_resource_t *resource,
376  oc_endpoint_t *endpoint);
377 
378 #ifdef __cplusplus
379 }
380 #endif
381 
382 #endif /* OC_KNX_SEC_INTERNAL_H */
bool oc_knx_sec_check_acl(oc_method_t method, const oc_resource_t *resource, oc_endpoint_t *endpoint)
check access control based on acl and resource interfaces
oc_auth_at_t * oc_get_auth_at_entry(size_t device_index, int index)
retrieve auth/at entry
int oc_core_get_at_table_size()
returns the size (amount of total entries) of the auth/at table
void oc_oscore_set_auth_mac(char *client_senderid, int client_senderid_size, char *clientrecipient_id, int clientrecipient_id_size, uint8_t *shared_key, int shared_key_size)
set shared (SPAKE) key to the auth at table, on the Management Client side
int oc_at_delete_entry(size_t device_index, int index)
delete the /auth/at table entry
int oc_core_find_at_entry_with_osc_id(size_t device_index, uint8_t *osc_id, size_t osc_id_len)
Find an entry with a given OSCORE ID.
void oc_init_oscore(size_t device_index)
initialize OSCORE for the device
oc_at_profile_t
The token profiles see section 3.5.4.2 Access Token Resource Object.
Definition: oc_knx_sec.h:36
@ OC_PROFILE_COAP_PASE
"coap_pase" [OSCORE] with PASE credentials
Definition: oc_knx_sec.h:42
@ OC_PROFILE_UNKNOWN
unknown profile
Definition: oc_knx_sec.h:37
@ OC_PROFILE_COAP_TLS
coap_tls" [OSCORE] for [X.509] certificates with TLS
Definition: oc_knx_sec.h:40
@ OC_PROFILE_COAP_OSCORE
"coap_oscore"
Definition: oc_knx_sec.h:39
@ OC_PROFILE_COAP_DTLS
"coap_dtls"
Definition: oc_knx_sec.h:38
int oc_core_find_at_entry_with_context_id(size_t device_index, char *context_id)
find the entry with context_id as id
char * oc_at_profile_to_string(oc_at_profile_t at_profile)
access token profile to string
void oc_create_knx_sec_resources(size_t device)
Creation of the KNX security resources.
void oc_init_oscore_from_storage(size_t device_index, bool from_storage)
initialize OSCORE for the device
int oc_core_set_at_table(size_t device_index, int index, oc_auth_at_t entry, bool store)
set an entry in the auth/at table
void oc_print_auth_at_entry(size_t device_index, int index)
print the auth/at entry
int oc_core_find_at_entry_empty_slot(size_t device_index)
find empty slot
bool oc_if_method_allowed_according_to_mask(oc_interface_mask_t iface_mask, oc_method_t method)
is the method allowed according to the interface mask
uint64_t oc_oscore_get_osndelay()
retrieve the oscore sequence number delay value
uint64_t oc_oscore_get_rplwdo()
retrieve the replay window
void oc_reset_at_table(size_t device_index, int erase_code)
reset the /auth/at table will be used in reset of the device erase_code:
struct oc_auth_at_t oc_auth_at_t
Access Token (at) Information payload for a unicast message Example(JSON):
oc_at_profile_t oc_string_to_at_profile(oc_string_t str)
string to access token profile
void oc_oscore_set_auth_device(char *client_senderid, int client_senderid_size, char *clientrecipient_id, int clientrecipient_id_size, uint8_t *shared_key, int shared_key_size)
set shared (SPAKE) key to the auth at table, on the Device side
bool oc_knx_contains_interface(oc_interface_mask_t at_interface, oc_interface_mask_t resource_interface)
function to check if the at_interface is listed in the resource interfaces
void oc_delete_at_table(size_t device_index)
delete the /auth/at table will be used in reset of the device
resource internals
oc_method_t
CoAP methods.
Definition: oc_ri.h:124
oc_interface_mask_t
interface masks security access scopes defined as interfaces note that scope = 1 is not used.
Definition: oc_ri.h:261
Access Token (at) Information payload for a unicast message Example(JSON):
Definition: oc_knx_sec.h:132
uint8_t osc_alg
(18:4:4) OSCORE cnf:osc:alg (optional- not used) default: decimal value 10
Definition: oc_knx_sec.h:144
oc_string_t osc_salt
(18:4:5) OSCORE cnf:osc:salt (optional) empty string
Definition: oc_knx_sec.h:147
oc_string_t kid
(8:2) DTLS (not used) cnf:kid
Definition: oc_knx_sec.h:139
int ga_len
length of the group addresses (ga) in the scope
Definition: oc_knx_sec.h:156
uint8_t osc_hkdf
(18:4:3) OSCORE cnf:osc:hkdf (optional-not used) (decimal value)
Definition: oc_knx_sec.h:142
oc_string_t osc_id
(18:4:0) OSCORE cnf:osc:id (used as SID & KID) (byte string), max 7 bytes
Definition: oc_knx_sec.h:151
oc_string_t id
(0) auth/at/{id}, encoding: HEX
Definition: oc_knx_sec.h:133
oc_string_t osc_rid
(18:4:7) OSCORE cnf:osc:rid (recipient ID) (byte string)
Definition: oc_knx_sec.h:154
int nbf
token not valid before (optional)
Definition: oc_knx_sec.h:155
oc_at_profile_t profile
(38) "coap_oscore" or "coap_dtls", only oscore implemented
Definition: oc_knx_sec.h:136
oc_string_t osc_ms
(18:4:2) OSCORE cnf:osc:ms (byte string)
Definition: oc_knx_sec.h:141
int64_t * ga
(scope) array of group addresses, for the group objects in the scope, int64_t for framing arrays
Definition: oc_knx_sec.h:157
oc_interface_mask_t scope
(9) the scope (interfaces)
Definition: oc_knx_sec.h:134
oc_string_t aud
not used anymore, references
Definition: oc_knx_sec.h:137
oc_string_t osc_version
(18:4:1) OSCORE cnf:osc:version (optional)
Definition: oc_knx_sec.h:140
oc_string_t sub
(2) DTLS (not used) 2 sub
Definition: oc_knx_sec.h:138
oc_string_t osc_contextid
(18:4:6) OSCORE cnf:osc:contextid used as "kid_context" (byte string, 6 bytes)
Definition: oc_knx_sec.h:148
the endpoint information
Definition: oc_endpoint.h:78
resource structure
Definition: oc_ri.h:482