libcoap 4.3.5b
Loading...
Searching...
No Matches
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-2025 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
17
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
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
164
165void
168
169void
173
178
179void *
181 return NULL;
182}
183
184void
187
188#if COAP_SERVER_SUPPORT
189void *
191 return NULL;
192}
193#endif /* COAP_SERVER_SUPPORT */
194
195#if COAP_CLIENT_SUPPORT
196void *
198 return NULL;
199}
200#endif /* COAP_CLIENT_SUPPORT */
201
202void
205
206void
209
210ssize_t
212 const uint8_t *data COAP_UNUSED,
213 size_t data_len COAP_UNUSED) {
214 return -1;
215}
216
217int
219 return 1;
220}
221
224 return 0;
225}
226
231
232/*
233 * return 1 timed out
234 * 0 still timing out
235 */
236int
240
241int
243 const uint8_t *data COAP_UNUSED,
244 size_t data_len COAP_UNUSED
245 ) {
246 return -1;
247}
248
249#if COAP_SERVER_SUPPORT
250int
252 const uint8_t *data COAP_UNUSED,
253 size_t data_len COAP_UNUSED
254 ) {
255 return 0;
256}
257#endif /* COAP_SERVER_SUPPORT */
258
259unsigned int
261 return 0;
262}
263
264#if COAP_CLIENT_SUPPORT
265void *
267 return NULL;
268}
269#endif /* COAP_CLIENT_SUPPORT */
270
271#if COAP_SERVER_SUPPORT
272void *
274 return NULL;
275}
276#endif /* COAP_SERVER_SUPPORT */
277
278void
281
282/*
283 * strm
284 * return +ve Number of bytes written.
285 * -1 Error (error in errno).
286 */
287ssize_t
289 const uint8_t *data COAP_UNUSED,
290 size_t data_len COAP_UNUSED) {
291 return -1;
292}
293
294/*
295 * strm
296 * return >=0 Number of bytes read.
297 * -1 Error (error in errno).
298 */
299ssize_t
301 uint8_t *data COAP_UNUSED,
302 size_t data_len COAP_UNUSED) {
303 return -1;
304}
305
306#if COAP_SERVER_SUPPORT
307typedef struct coap_local_hash_t {
308 size_t ofs;
309 coap_key_t key[8]; /* 32 bytes in total */
310} coap_local_hash_t;
311
313coap_digest_setup(void) {
314 coap_key_t *digest_ctx = coap_malloc_type(COAP_DIGEST_CTX, sizeof(coap_local_hash_t));
315
316 if (digest_ctx) {
317 memset(digest_ctx, 0, sizeof(coap_local_hash_t));
318 }
319
320 return digest_ctx;
321}
322
323void
325 coap_free_type(COAP_DIGEST_CTX, digest_ctx);
326}
327
328int
330 const uint8_t *data,
331 size_t data_len) {
332 coap_local_hash_t *local = (coap_local_hash_t *)digest_ctx;
333
334 coap_hash(data, data_len, local->key[local->ofs]);
335
336 local->ofs = (local->ofs + 1) % 7;
337 return 1;
338}
339
340int
342 coap_digest_t *digest_buffer) {
343 coap_local_hash_t *local = (coap_local_hash_t *)digest_ctx;
344
345 memcpy(digest_buffer, local->key, sizeof(coap_digest_t));
346
347 coap_digest_free(digest_ctx);
348 return 1;
349}
350#endif /* COAP_SERVER_SUPPORT */
351
352#if COAP_WS_SUPPORT
353int
355 const coap_bin_const_t *data,
356 coap_bin_const_t **hash) {
357 SHA1Context sha1_context;
358 coap_binary_t *dummy = NULL;
359
360 (void)alg;
361
362 SHA1Reset(&sha1_context);
363 if (SHA1Input(&sha1_context, data->s, data->length) != shaSuccess)
364 return 0;
366 if (!dummy)
367 return 0;
368 if (SHA1Result(&sha1_context, dummy->s) != shaSuccess) {
370 return 0;
371 }
372 *hash = (coap_bin_const_t *)(dummy);
373 return 1;
374}
375#endif /* COAP_WS_SUPPORT */
376
377#if COAP_OSCORE_SUPPORT
378
379int
381 return 0;
382}
383
384int
386 (void)alg;
387 return 0;
388}
389
390int
392 (void)hkdf_alg;
393 return 0;
394}
395
396int
398 coap_bin_const_t *data,
399 coap_bin_const_t *aad,
400 uint8_t *result,
401 size_t *max_result_len) {
402 (void)params;
403 (void)data;
404 (void)aad;
405 (void)result;
406 *max_result_len = 0;
407 return 0;
408}
409
410int
412 coap_bin_const_t *data,
413 coap_bin_const_t *aad,
414 uint8_t *result,
415 size_t *max_result_len) {
416 (void)params;
417 (void)data;
418 (void)aad;
419 (void)result;
420 *max_result_len = 0;
421 return 0;
422}
423
424int
426 coap_bin_const_t *key,
427 coap_bin_const_t *data,
428 coap_bin_const_t **hmac) {
429 (void)hmac_alg;
430 (void)key;
431 (void)data;
432 (void)hmac;
433 return 0;
434}
435
436#endif /* COAP_OSCORE_SUPPORT */
437
438#else /* !COAP_WITH_LIBTINYDTLS && !COAP_WITH_LIBOPENSSL && !COAP_WITH_LIBWOLFSSL && !COAP_WITH_LIBGNUTLS */
439
440#ifdef __clang__
441/* Make compilers happy that do not like empty modules. As this function is
442 * never used, we ignore -Wunused-function at the end of compiling this file
443 */
444#pragma GCC diagnostic ignored "-Wunused-function"
445#endif
446static inline void
447dummy(void) {
448}
449
450#endif /* !COAP_WITH_LIBTINYDTLS && !COAP_WITH_LIBOPENSSL && !COAP_WITH_LIBWOLFSSL && !COAP_WITH_LIBGNUTLS && !COAP_WITH_LIBMBEDTLS */
static void dummy(void)
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:228
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:300
coap_tick_t coap_dtls_get_context_timeout(void *dtls_context COAP_UNUSED)
Definition coap_notls.c:223
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:242
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:260
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:211
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:288
void coap_dtls_session_update_mtu(coap_session_t *session COAP_UNUSED)
Definition coap_notls.c:207
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:237
void coap_dtls_free_context(void *handle COAP_UNUSED)
Definition coap_notls.c:185
void coap_dtls_free_session(coap_session_t *coap_session COAP_UNUSED)
Definition coap_notls.c:203
void * coap_dtls_new_context(coap_context_t *coap_context COAP_UNUSED)
Definition coap_notls.c:180
void coap_tls_free_session(coap_session_t *coap_session COAP_UNUSED)
Definition coap_notls.c:279
int SHA1Result(SHA1Context *, uint8_t Message_Digest[SHA1HashSize])
int SHA1Reset(SHA1Context *)
@ shaSuccess
int SHA1Input(SHA1Context *, const uint8_t *, unsigned int)
#define SHA1HashSize
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_thread_shutdown(void)
Close down the underlying (D)TLS Library layer.
Definition coap_notls.c:166
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:218
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:175
void coap_dtls_set_log_level(coap_log_t level)
Sets the (D)TLS logging level to the specified level.
Definition coap_notls.c:170
@ COAP_LOG_EMERG
Definition coap_debug.h:51
cose_hkdf_alg_t
cose_hmac_alg_t
cose_alg_t
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.
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