libcoap 4.3.5-develop-19cef11
coap_notls.c
Go to the documentation of this file.
1/*
2 * coap_notls.c -- Stub Datagram Transport Layer Support for libcoap
3 *
4 * Copyright (C) 2016 Olaf Bergmann <bergmann@tzi.org>
5 * Copyright (C) 2021-2024 Jon Shallow <supjps-libcoap@jpshallow.com>
6 *
7 * SPDX-License-Identifier: BSD-2-Clause
8 *
9 * This file is part of the CoAP library libcoap. Please see README for terms
10 * of use.
11 */
12
19
20#if !defined(COAP_WITH_LIBOPENSSL)
21int
23 (void)conf_mem;
24 return 0;
25}
26
27int
29 return 0;
30}
31#endif /* ! COAP_WITH_LIBOPENSSL */
32
33#if !defined(COAP_WITH_LIBTINYDTLS) && !defined(COAP_WITH_LIBOPENSSL) && !defined(COAP_WITH_LIBWOLFSSL) && !defined(COAP_WITH_LIBGNUTLS) && !defined(COAP_WITH_LIBMBEDTLS)
34
35int
37 return 0;
38}
39
40int
42 return 0;
43}
44
45/*
46 * return 0 failed
47 * 1 passed
48 */
49int
51 return 0;
52}
53
54/*
55 * return 0 failed
56 * 1 passed
57 */
58int
60 return 0;
61}
62
63/*
64 * return 0 failed
65 * 1 passed
66 */
67int
69 return 0;
70}
71
72/*
73 * return 0 failed
74 * 1 passed
75 */
76int
78 return 0;
79}
80
81/*
82 * return 0 failed
83 * 1 passed
84 */
85int
87 return 0;
88}
89
90#if COAP_CLIENT_SUPPORT
91int
92coap_dtls_set_cid_tuple_change(coap_context_t *c_context, uint8_t every) {
93 (void)c_context;
94 (void)every;
95 return 0;
96}
97#endif /* COAP_CLIENT_SUPPORT */
98
101 static coap_tls_version_t version;
102 version.version = 0;
104 return &version;
105}
106
107int
109 const coap_dtls_pki_t *setup_data COAP_UNUSED,
111 ) {
112 return 0;
113}
114
115int
117 const char *ca_file COAP_UNUSED,
118 const char *ca_path COAP_UNUSED
119 ) {
120 return 0;
121}
122
123#if COAP_CLIENT_SUPPORT
124int
126 coap_dtls_cpsk_t *setup_data COAP_UNUSED
127 ) {
128 return 0;
129}
130#endif /* COAP_CLIENT_SUPPORT */
131
132#if COAP_SERVER_SUPPORT
133int
135 coap_dtls_spsk_t *setup_data COAP_UNUSED
136 ) {
137 return 0;
138}
139#endif /* COAP_SERVER_SUPPORT */
140
141int
143 return 0;
144}
145
147
148void
150}
151
152void *
154 coap_tls_library_t *tls_lib) {
155 if (tls_lib)
156 *tls_lib = COAP_TLS_LIBRARY_NOTLS;
157 return NULL;
158}
159
160void
163}
164
165void
167 dtls_log_level = level;
168}
169
172 return dtls_log_level;
173}
174
175void *
177 return NULL;
178}
179
180void
182}
183
184#if COAP_SERVER_SUPPORT
185void *
187 return NULL;
188}
189#endif /* COAP_SERVER_SUPPORT */
190
191#if COAP_CLIENT_SUPPORT
192void *
194 return NULL;
195}
196#endif /* COAP_CLIENT_SUPPORT */
197
198void
200}
201
202void
204}
205
206ssize_t
208 const uint8_t *data COAP_UNUSED,
209 size_t data_len COAP_UNUSED) {
210 return -1;
211}
212
213int
215 return 1;
216}
217
220 return 0;
221}
222
225 return 0;
226}
227
228/*
229 * return 1 timed out
230 * 0 still timing out
231 */
232int
234 return 0;
235}
236
237int
239 const uint8_t *data COAP_UNUSED,
240 size_t data_len COAP_UNUSED
241 ) {
242 return -1;
243}
244
245#if COAP_SERVER_SUPPORT
246int
248 const uint8_t *data COAP_UNUSED,
249 size_t data_len COAP_UNUSED
250 ) {
251 return 0;
252}
253#endif /* COAP_SERVER_SUPPORT */
254
255unsigned int
257 return 0;
258}
259
260#if COAP_CLIENT_SUPPORT
261void *
263 return NULL;
264}
265#endif /* COAP_CLIENT_SUPPORT */
266
267#if COAP_SERVER_SUPPORT
268void *
270 return NULL;
271}
272#endif /* COAP_SERVER_SUPPORT */
273
274void
276}
277
278/*
279 * strm
280 * return +ve Number of bytes written.
281 * -1 Error (error in errno).
282 */
283ssize_t
285 const uint8_t *data COAP_UNUSED,
286 size_t data_len COAP_UNUSED) {
287 return -1;
288}
289
290/*
291 * strm
292 * return >=0 Number of bytes read.
293 * -1 Error (error in errno).
294 */
295ssize_t
297 uint8_t *data COAP_UNUSED,
298 size_t data_len COAP_UNUSED) {
299 return -1;
300}
301
302#if COAP_SERVER_SUPPORT
303typedef struct coap_local_hash_t {
304 size_t ofs;
305 coap_key_t key[8]; /* 32 bytes in total */
306} coap_local_hash_t;
307
309coap_digest_setup(void) {
310 coap_key_t *digest_ctx = coap_malloc_type(COAP_DIGEST_CTX, sizeof(coap_local_hash_t));
311
312 if (digest_ctx) {
313 memset(digest_ctx, 0, sizeof(coap_local_hash_t));
314 }
315
316 return digest_ctx;
317}
318
319void
321 coap_free_type(COAP_DIGEST_CTX, digest_ctx);
322}
323
324int
326 const uint8_t *data,
327 size_t data_len) {
328 coap_local_hash_t *local = (coap_local_hash_t *)digest_ctx;
329
330 coap_hash(data, data_len, local->key[local->ofs]);
331
332 local->ofs = (local->ofs + 1) % 7;
333 return 1;
334}
335
336int
338 coap_digest_t *digest_buffer) {
339 coap_local_hash_t *local = (coap_local_hash_t *)digest_ctx;
340
341 memcpy(digest_buffer, local->key, sizeof(coap_digest_t));
342
343 coap_digest_free(digest_ctx);
344 return 1;
345}
346#endif /* COAP_SERVER_SUPPORT */
347
348#if COAP_WS_SUPPORT
349int
351 const coap_bin_const_t *data,
352 coap_bin_const_t **hash) {
353 SHA1Context sha1_context;
354 coap_binary_t *dummy = NULL;
355
356 (void)alg;
357
358 SHA1Reset(&sha1_context);
359 if (SHA1Input(&sha1_context, data->s, data->length) != shaSuccess)
360 return 0;
362 if (!dummy)
363 return 0;
364 if (SHA1Result(&sha1_context, dummy->s) != shaSuccess) {
366 return 0;
367 }
368 *hash = (coap_bin_const_t *)(dummy);
369 return 1;
370}
371#endif /* COAP_WS_SUPPORT */
372
373#if COAP_OSCORE_SUPPORT
374
375int
377 return 0;
378}
379
380int
382 (void)alg;
383 return 0;
384}
385
386int
388 (void)hkdf_alg;
389 return 0;
390}
391
392int
394 coap_bin_const_t *data,
395 coap_bin_const_t *aad,
396 uint8_t *result,
397 size_t *max_result_len) {
398 (void)params;
399 (void)data;
400 (void)aad;
401 (void)result;
402 *max_result_len = 0;
403 return 0;
404}
405
406int
408 coap_bin_const_t *data,
409 coap_bin_const_t *aad,
410 uint8_t *result,
411 size_t *max_result_len) {
412 (void)params;
413 (void)data;
414 (void)aad;
415 (void)result;
416 *max_result_len = 0;
417 return 0;
418}
419
420int
422 coap_bin_const_t *key,
423 coap_bin_const_t *data,
424 coap_bin_const_t **hmac) {
425 (void)hmac_alg;
426 (void)key;
427 (void)data;
428 (void)hmac;
429 return 0;
430}
431
432#endif /* COAP_OSCORE_SUPPORT */
433
434#else /* !COAP_WITH_LIBTINYDTLS && !COAP_WITH_LIBOPENSSL && !COAP_WITH_LIBWOLFSSL && !COAP_WITH_LIBGNUTLS */
435
436#ifdef __clang__
437/* Make compilers happy that do not like empty modules. As this function is
438 * never used, we ignore -Wunused-function at the end of compiling this file
439 */
440#pragma GCC diagnostic ignored "-Wunused-function"
441#endif
442static inline void
443dummy(void) {
444}
445
446#endif /* !COAP_WITH_LIBTINYDTLS && !COAP_WITH_LIBOPENSSL && !COAP_WITH_LIBWOLFSSL && !COAP_WITH_LIBGNUTLS && !COAP_WITH_LIBMBEDTLS */
unsigned char coap_key_t[4]
#define coap_hash(String, Length, Result)
Library specific build wrapper for coap_internal.h.
@ COAP_DIGEST_CTX
Definition: coap_mem.h:58
void * coap_malloc_type(coap_memory_tag_t type, size_t size)
Allocates a chunk of size bytes and returns a pointer to the newly allocated memory.
void coap_free_type(coap_memory_tag_t type, void *p)
Releases the memory that was allocated by coap_malloc_type().
int coap_dtls_context_set_pki(coap_context_t *ctx COAP_UNUSED, const coap_dtls_pki_t *setup_data COAP_UNUSED, const coap_dtls_role_t role COAP_UNUSED)
Definition: coap_notls.c:108
coap_tick_t coap_dtls_get_timeout(coap_session_t *session COAP_UNUSED, coap_tick_t now COAP_UNUSED)
Definition: coap_notls.c:224
ssize_t coap_tls_read(coap_session_t *session COAP_UNUSED, uint8_t *data COAP_UNUSED, size_t data_len COAP_UNUSED)
Definition: coap_notls.c:296
coap_tick_t coap_dtls_get_context_timeout(void *dtls_context COAP_UNUSED)
Definition: coap_notls.c:219
int coap_dtls_receive(coap_session_t *session COAP_UNUSED, const uint8_t *data COAP_UNUSED, size_t data_len COAP_UNUSED)
Definition: coap_notls.c:238
void * coap_dtls_get_tls(const coap_session_t *c_session COAP_UNUSED, coap_tls_library_t *tls_lib)
Definition: coap_notls.c:153
unsigned int coap_dtls_get_overhead(coap_session_t *session COAP_UNUSED)
Definition: coap_notls.c:256
static coap_log_t dtls_log_level
Definition: coap_notls.c:146
int coap_dtls_context_check_keys_enabled(coap_context_t *ctx COAP_UNUSED)
Definition: coap_notls.c:142
ssize_t coap_dtls_send(coap_session_t *session COAP_UNUSED, const uint8_t *data COAP_UNUSED, size_t data_len COAP_UNUSED)
Definition: coap_notls.c:207
ssize_t coap_tls_write(coap_session_t *session COAP_UNUSED, const uint8_t *data COAP_UNUSED, size_t data_len COAP_UNUSED)
Definition: coap_notls.c:284
void coap_dtls_session_update_mtu(coap_session_t *session COAP_UNUSED)
Definition: coap_notls.c:203
int coap_dtls_context_set_pki_root_cas(coap_context_t *ctx COAP_UNUSED, const char *ca_file COAP_UNUSED, const char *ca_path COAP_UNUSED)
Definition: coap_notls.c:116
int coap_dtls_handle_timeout(coap_session_t *session COAP_UNUSED)
Definition: coap_notls.c:233
void coap_dtls_free_context(void *handle COAP_UNUSED)
Definition: coap_notls.c:181
void coap_dtls_free_session(coap_session_t *coap_session COAP_UNUSED)
Definition: coap_notls.c:199
void * coap_dtls_new_context(coap_context_t *coap_context COAP_UNUSED)
Definition: coap_notls.c:176
void coap_tls_free_session(coap_session_t *coap_session COAP_UNUSED)
Definition: coap_notls.c:275
int SHA1Result(SHA1Context *, uint8_t Message_Digest[SHA1HashSize])
int SHA1Reset(SHA1Context *)
int SHA1Input(SHA1Context *, const uint8_t *, unsigned int)
@ shaSuccess
#define SHA1HashSize
COAP_STATIC_INLINE void dummy(void)
Definition: coap_time.c:144
void coap_digest_free(coap_digest_ctx_t *digest_ctx)
Free off coap_digest_ctx_t.
int coap_digest_final(coap_digest_ctx_t *digest_ctx, coap_digest_t *digest_buffer)
Finalize the coap_digest information into the provided digest_buffer.
int coap_digest_update(coap_digest_ctx_t *digest_ctx, const uint8_t *data, size_t data_len)
Update the coap_digest information with the next chunk of data.
void coap_digest_ctx_t
coap_digest_ctx_t * coap_digest_setup(void)
Initialize a coap_digest.
uint64_t coap_tick_t
This data type represents internal timer ticks with COAP_TICKS_PER_SECOND resolution.
Definition: coap_time.h:143
int coap_crypto_hmac(cose_hmac_alg_t hmac_alg, coap_bin_const_t *key, coap_bin_const_t *data, coap_bin_const_t **hmac)
Create a HMAC hash of the provided data.
int coap_crypto_aead_decrypt(const coap_crypto_param_t *params, coap_bin_const_t *data, coap_bin_const_t *aad, uint8_t *result, size_t *max_result_len)
Decrypt the provided encrypted data into plaintext.
int coap_crypto_aead_encrypt(const coap_crypto_param_t *params, coap_bin_const_t *data, coap_bin_const_t *aad, uint8_t *result, size_t *max_result_len)
Encrypt the provided plaintext data.
int coap_crypto_hash(cose_alg_t alg, const coap_bin_const_t *data, coap_bin_const_t **hash)
Create a hash of the provided data.
int coap_crypto_check_hkdf_alg(cose_hkdf_alg_t hkdf_alg)
Check whether the defined hkdf algorithm is supported by the underlying crypto library.
int coap_crypto_check_cipher_alg(cose_alg_t alg)
Check whether the defined cipher algorithm is supported by the underlying crypto library.
void * coap_tls_new_server_session(coap_session_t *coap_session)
Create a TLS new server-side session.
void coap_dtls_startup(void)
Initialize the underlying (D)TLS Library layer.
Definition: coap_notls.c:149
void * coap_dtls_new_client_session(coap_session_t *coap_session)
Create a new client-side session.
void * coap_dtls_new_server_session(coap_session_t *coap_session)
Create a new DTLS server-side session.
int coap_dtls_hello(coap_session_t *coap_session, const uint8_t *data, size_t data_len)
Handling client HELLO messages from a new candiate peer.
int coap_dtls_set_cid_tuple_change(coap_context_t *context, uint8_t every)
Set the Connection ID client tuple frequency change for testing CIDs.
int coap_dtls_is_context_timeout(void)
Check if timeout is handled per CoAP session or per CoAP context.
Definition: coap_notls.c:214
int coap_dtls_context_set_cpsk(coap_context_t *coap_context, coap_dtls_cpsk_t *setup_data)
Set the DTLS context's default client PSK information.
int coap_dtls_context_set_spsk(coap_context_t *coap_context, coap_dtls_spsk_t *setup_data)
Set the DTLS context's default server PSK information.
void coap_dtls_shutdown(void)
Close down the underlying (D)TLS Library layer.
Definition: coap_notls.c:161
void * coap_tls_new_client_session(coap_session_t *coap_session)
Create a new TLS client-side session.
int coap_tls_engine_configure(coap_str_const_t *conf_mem)
Configure an ENGINE for a TLS library.
Definition: coap_notls.c:22
coap_tls_version_t * coap_get_tls_library_version(void)
Determine the type and version of the underlying (D)TLS library.
Definition: coap_notls.c:100
coap_dtls_role_t
Definition: coap_dtls.h:44
int coap_tls_engine_remove(void)
Remove a previously configured ENGINE from a TLS library.
Definition: coap_notls.c:28
coap_tls_library_t
Definition: coap_dtls.h:70
@ COAP_TLS_LIBRARY_NOTLS
No DTLS library.
Definition: coap_dtls.h:71
coap_log_t
Logging type.
Definition: coap_debug.h:50
coap_log_t coap_dtls_get_log_level(void)
Get the current (D)TLS logging.
Definition: coap_notls.c:171
void coap_dtls_set_log_level(coap_log_t level)
Sets the (D)TLS logging level to the specified level.
Definition: coap_notls.c:166
@ COAP_LOG_EMERG
Definition: coap_debug.h:51
cose_hkdf_alg_t
Definition: oscore_cose.h:165
cose_hmac_alg_t
Definition: oscore_cose.h:157
cose_alg_t
Definition: oscore_cose.h:126
coap_binary_t * coap_new_binary(size_t size)
Returns a new binary object with at least size bytes storage allocated.
Definition: coap_str.c:77
void coap_delete_binary(coap_binary_t *s)
Deletes the given coap_binary_t object and releases any memory allocated.
Definition: coap_str.c:105
int coap_dtls_cid_is_supported(void)
Check whether (D)TLS CID is available.
Definition: coap_notls.c:86
int coap_dtls_psk_is_supported(void)
Check whether (D)TLS PSK is available.
Definition: coap_notls.c:50
int coap_tls_is_supported(void)
Check whether TLS is available.
Definition: coap_notls.c:41
int coap_oscore_is_supported(void)
Check whether OSCORE is available.
Definition: coap_oscore.c:2195
int coap_dtls_is_supported(void)
Check whether DTLS is available.
Definition: coap_notls.c:36
int coap_dtls_pki_is_supported(void)
Check whether (D)TLS PKI is available.
Definition: coap_notls.c:59
int coap_dtls_rpk_is_supported(void)
Check whether (D)TLS RPK is available.
Definition: coap_notls.c:77
int coap_dtls_pkcs11_is_supported(void)
Check whether (D)TLS PKCS11 is available.
Definition: coap_notls.c:68
#define COAP_UNUSED
Definition: libcoap.h:70
CoAP binary data definition with const data.
Definition: coap_str.h:64
size_t length
length of binary data
Definition: coap_str.h:65
const uint8_t * s
read-only binary data
Definition: coap_str.h:66
CoAP binary data definition.
Definition: coap_str.h:56
The CoAP stack's global state is stored in a coap_context_t object.
The common structure that holds the Crypto information.
The structure used for defining the Client PSK setup data to be used.
Definition: coap_dtls.h:410
The structure used for defining the PKI setup data to be used.
Definition: coap_dtls.h:312
The structure used for defining the Server PSK setup data to be used.
Definition: coap_dtls.h:501
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:46
The structure used for returning the underlying (D)TLS library information.
Definition: coap_dtls.h:83
coap_tls_library_t type
Library type.
Definition: coap_dtls.h:85
uint64_t version
(D)TLS runtime Library Version
Definition: coap_dtls.h:84