libcoap 4.3.5-develop-5347a62
Loading...
Searching...
No Matches
oscore_context.h
Go to the documentation of this file.
1/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
3/*
4 * Copyright (c) 2018, SICS, RISE AB
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the Institute nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 */
32
47
48#ifndef _OSCORE_CONTEXT_H
49#define _OSCORE_CONTEXT_H
50
51#include "coap3/coap_uthash_internal.h"
52#include "oscore/oscore_cose.h"
53
54#ifdef __cplusplus
55extern "C" {
56#endif
57
63
64#define TOKEN_SEQ_NUM 2 /* to be set by application */
65#define EP_CTX_NUM 10 /* to be set by application */
66#define CONTEXT_SEQ_LEN sizeof(uint64_t)
67
68#define ED25519_PRIVATE_KEY_LEN 32
69#define ED25519_PUBLIC_KEY_LEN 32
70#define ED25519_SEED_LEN 32
71#define ED25519_SIGNATURE_LEN 64
72
73#define OSCORE_SEQ_MAX (((uint64_t)1 << 40) - 1)
74
80
84
85#if COAP_OSCORE_GROUP_SUPPORT
86typedef enum {
87 OSCORE_AUTH_CRED_UNKNOWN = 0,
88 OSCORE_AUTH_CRED_CWT,
89 OSCORE_AUTH_CRED_CCS,
90 OSCORE_AUTH_CRED_X509,
91 OSCORE_AUTH_CRED_C509
92} oscore_auth_cred_t;
93#endif /* COAP_OSCORE_GROUP_SUPPORT */
94
97 /* RFC8613 3.1 */
107 /* RFC8613 B.1.2 */
109 /* RFC8613 B.2 */
110 uint8_t rfc8613_b_2;
112 /* Tracking */
113 uint32_t ssn_freq;
117#if COAP_OSCORE_GROUP_SUPPORT
118 /* RFCxxxx 2. */
119 oscore_auth_cred_t auth_cred_fmt;
120 coap_crypto_cred_t *gm_cred;
121 cose_alg_t alg_group_enc;
122 cose_alg_t alg_signature;
123 coap_bin_const_t *sign_enc_key;
124 cose_alg_t alg_pairwise_key_agreement;
125 coap_bin_const_t *sign_params;
126#endif /* COAP_OSCORE_GROUP_SUPPORT */
127};
128
133
135 /* RFC8613 3.1 */
138 uint64_t seq;
139 /* Tracking */
140 uint64_t next_seq;
141#if COAP_OSCORE_GROUP_SUPPORT
142 /* RFCxxxx 2. */
143 int group_mode;
144 int pairwise_mode;
145 coap_crypto_pri_key_t *my_private_key;
146 coap_crypto_cred_t *sender_cred;
147 oscore_pw_chain_t *pw_sender_key_chain;
148#endif /* COAP_OSCORE_GROUP_SUPPORT */
149};
150
152 unsigned ref;
156 /* RFC8613 3.1 */
159 uint64_t last_seq;
160 /* uint64_t highest_seq; */
164 uint8_t echo_value[8];
170#if COAP_OSCORE_GROUP_SUPPORT
171 /* RFCxxxx 2. */
172 coap_crypto_cred_t *rem_cred;
173 coap_bin_const_t *pw_rem_recipient_key;
174#endif /* COAP_OSCORE_GROUP_SUPPORT */
175};
176
177#define OSCORE_ASSOCIATIONS_ADD(r, obj) \
178 HASH_ADD(hh, (r), token->s[0], (obj)->token->length, (obj))
179
180#define OSCORE_ASSOCIATIONS_DELETE(r, obj) HASH_DELETE(hh, (r), (obj))
181
182#define OSCORE_ASSOCIATIONS_ITER(r, tmp) \
183 oscore_associations_t *tmp, *rtmp; \
184 HASH_ITER (hh, (r), tmp, rtmp)
185
186#define OSCORE_ASSOCIATIONS_ITER_SAFE(e, el, rtmp) \
187 for ((el) = (e); (el) && ((rtmp) = (el)->hh.next, 1); (el) = (rtmp))
188
189#define OSCORE_ASSOCIATIONS_FIND(r, k, res) \
190 { HASH_FIND(hh, (r), (k)->s, (k)->length, (res)); }
191
205
216 coap_oscore_conf_t *oscore_conf);
217
226
240 oscore_ctx_t *o_osc_ctx,
241 coap_bin_const_t *sender_id,
242 coap_bin_const_t *recipient_id,
243 coap_bin_const_t *id_context);
244
252
254
256
258
260
268
280 coap_oscore_rcp_conf_t *rcp_conf,
281 uint32_t break_key);
282
284
286
295
302
303uint8_t oscore_bytes_equal(uint8_t *a_ptr,
304 uint8_t a_len,
305 uint8_t *b_ptr,
306 uint8_t b_len);
307
308void oscore_convert_to_hex(const uint8_t *src,
309 size_t src_len,
310 char *dest,
311 size_t dst_len);
312
314 const char *name,
315 coap_bin_const_t *value);
316
317void oscore_log_int_value(coap_log_t level, const char *name, int value);
318
319void oscore_log_char_value(coap_log_t level, const char *name,
320 const char *value);
321
338 const coap_bin_const_t rcpkey_id,
339 const coap_bin_const_t *ctxkey_id,
340 uint8_t *oscore_r2,
341 oscore_recipient_ctx_t **recipient_ctx);
342
355 const coap_bin_const_t rcpkey_id,
356 const coap_bin_const_t *ctxkey_id,
357 uint8_t *oscore_r2,
358 oscore_recipient_ctx_t **recipient_ctx);
359
361
363
365 coap_pdu_t *sent_pdu,
366 coap_bin_const_t *token,
367 oscore_recipient_ctx_t *recipient_ctx,
368 coap_bin_const_t *aad,
369 coap_bin_const_t *nonce,
370 coap_bin_const_t *partial_iv,
371 int is_observe);
372
374 coap_bin_const_t *token);
375
377 oscore_association_t *association);
378
380
382 cose_encrypt0_t *code,
383 uint8_t coap_request,
384 coap_bin_const_t *sender_key,
385 coap_bin_const_t *id_context,
386 size_t cs_size,
387 uint8_t *keystream,
388 size_t keystream_size);
389
391 coap_bin_const_t *salt,
392 coap_bin_const_t *ikm,
393 cose_alg_t aead_alg,
395 coap_str_const_t *type,
396 size_t out_len);
397
399
400#ifdef __cplusplus
401}
402#endif
403
404#endif /* _OSCORE_CONTEXT_H */
uint64_t coap_tick_t
This data type represents internal timer ticks with COAP_TICKS_PER_SECOND resolution.
Definition coap_time.h:149
coap_log_t
Logging type.
Definition coap_debug.h:56
cose_hkdf_alg_t
cose_alg_t
void oscore_reference_recipient_ctx(oscore_recipient_ctx_t *recipient_ctx)
Increment the recipient context reference count.
void oscore_convert_to_hex(const uint8_t *src, size_t src_len, char *dest, size_t dst_len)
oscore_ctx_t * oscore_derive_ctx_from_conf(coap_oscore_conf_t *oscore_conf)
oscore_derive_ctx_from_conf - derive a osc_ctx from oscore_conf information
int oscore_delete_association(coap_session_t *session, oscore_association_t *association)
void oscore_enter_context(coap_context_t *c_context, oscore_ctx_t *osc_ctx)
oscore_recipient_ctx_t * oscore_add_recipient(oscore_ctx_t *ctx, coap_oscore_rcp_conf_t *rcp_conf, uint32_t break_key)
oscore_add_recipient - add in recipient information
int oscore_add_context(coap_context_t *c_context, oscore_ctx_t *osc_ctx)
void oscore_free_sender(oscore_sender_ctx_t *snd_ctx)
coap_bin_const_t * oscore_build_key(oscore_ctx_t *osc_ctx, coap_bin_const_t *salt, coap_bin_const_t *ikm, cose_alg_t aead_alg, coap_bin_const_t *id, coap_str_const_t *type, size_t out_len)
int oscore_delete_recipient(oscore_ctx_t *osc_ctx, coap_bin_const_t *rid)
oscore_mode_t
oscore_ctx_t * oscore_find_context_in_ram(const coap_context_t *c_context, const coap_bin_const_t rcpkey_id, const coap_bin_const_t *ctxkey_id, uint8_t *oscore_r2, oscore_recipient_ctx_t **recipient_ctx)
Locate an OSCORE security context in libcoap's in-RAM registry only.
void oscore_update_ctx(oscore_ctx_t *osc_ctx, coap_bin_const_t *id_context)
oscore_update_ctx - update a osc_ctx with a new id_context
void oscore_free_context(oscore_ctx_t *osc_ctx)
oscore_ctx_t * oscore_derive_ctx(coap_context_t *c_context, coap_oscore_conf_t *oscore_conf)
oscore_derive_ctx - derive a osc_ctx from oscore_conf information
void oscore_free_association(oscore_association_t *association)
int oscore_new_association(coap_session_t *session, coap_pdu_t *sent_pdu, coap_bin_const_t *token, oscore_recipient_ctx_t *recipient_ctx, coap_bin_const_t *aad, coap_bin_const_t *nonce, coap_bin_const_t *partial_iv, int is_observe)
void oscore_delete_server_associations(coap_session_t *session)
void oscore_log_char_value(coap_log_t level, const char *name, const char *value)
oscore_ctx_t * oscore_find_context(coap_session_t *session, const coap_bin_const_t rcpkey_id, const coap_bin_const_t *ctxkey_id, uint8_t *oscore_r2, oscore_recipient_ctx_t **recipient_ctx)
oscore_find_context - Locate recipient context (and hence OSCORE context)
void oscore_free_contexts(coap_context_t *c_context)
void oscore_log_hex_value(coap_log_t level, const char *name, coap_bin_const_t *value)
void oscore_log_int_value(coap_log_t level, const char *name, int value)
int oscore_is_context_attached(const oscore_ctx_t *osc_ctx)
Check if oscore context is attached to a the provided context.
oscore_ctx_t * oscore_duplicate_ctx(coap_context_t *c_context, oscore_ctx_t *o_osc_ctx, coap_bin_const_t *sender_id, coap_bin_const_t *recipient_id, coap_bin_const_t *id_context)
oscore_duplicate_ctx - duplicate a osc_ctx
int oscore_remove_context(coap_context_t *c_context, oscore_ctx_t *osc_ctx)
int oscore_derive_keystream(oscore_ctx_t *osc_ctx, cose_encrypt0_t *code, uint8_t coap_request, coap_bin_const_t *sender_key, coap_bin_const_t *id_context, size_t cs_size, uint8_t *keystream, size_t keystream_size)
oscore_association_t * oscore_find_association(coap_session_t *session, coap_bin_const_t *token)
uint8_t oscore_bytes_equal(uint8_t *a_ptr, uint8_t a_len, uint8_t *b_ptr, uint8_t b_len)
void oscore_release_recipient_ctx(oscore_recipient_ctx_t **recipient_ctx)
Cleanup recipient context, including releasing the oscore context if the oscore context referenced is...
@ OSCORE_MODE_SINGLE
Vanilla RFC 8613 support.
@ OSCORE_MODE_PAIRWISE
RFC 10021 support.
@ OSCORE_MODE_GROUP
RFC 10021 support.
int(* coap_oscore_save_seq_num_t)(uint64_t sender_seq_num, void *param)
Definition of the function used to save the current Sender Sequence Number.
An implementation of the CBOR Object Signing and Encryption (RFC).
CoAP binary data definition with const data.
Definition coap_str.h:65
The CoAP stack's global state is stored in a coap_context_t object.
Holds credential definitions.
Holds private key definitions.
The structure used to hold the OSCORE configuration information.
The structure used to hold the OSCORE Recipient configuration.
structure for CoAP PDUs
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...
CoAP string data definition with const data.
Definition coap_str.h:47
coap_bin_const_t * obs_partial_iv
coap_bin_const_t * partial_iv
coap_bin_const_t * aad
coap_bin_const_t * nonce
oscore_recipient_ctx_t * recipient_ctx
coap_bin_const_t * token
coap_bin_const_t * master_secret
uint32_t replay_window_size
coap_bin_const_t * common_iv
Derived from Master Secret, Master Salt, and ID Context.
struct oscore_ctx_t * next
uint8_t rfc8613_b_1_2
1 if rfc8613 B.1.2 enabled else 0
void * save_seq_num_func_param
Passed to save_seq_num_func().
oscore_sender_ctx_t * sender_context
cose_hkdf_alg_t hkdf_alg
Set to one of COSE_HKDF_ALG_*.
cose_alg_t aead_alg
Set to one of COSE_ALGORITHM_AES*.
uint8_t rfc8613_b_2
1 if rfc8613 B.2 protocol else 0
coap_bin_const_t * master_salt
coap_oscore_save_seq_num_t save_seq_num_func
Called every seq num change.
oscore_recipient_ctx_t * recipient_chain
coap_bin_const_t * id_context
contains GID in case of group
uint32_t ssn_freq
Sender Seq Num update frequency.
coap_bin_const_t * pw_sender_key
struct oscore_pw_chain_t * next
oscore_recipient_ctx_t * next_recipient
This field allows recipient chaining.
unsigned ref
Reference counter to keep track of linked associations / active sessions.
coap_bin_const_t * recipient_key
coap_bin_const_t * recipient_id
coap_bin_const_t * sender_id
uint64_t seq
Sender Sequence Number.
coap_bin_const_t * sender_key
uint64_t next_seq
Used for ssn_freq updating.