libcoap 4.3.5-develop-0a48cee
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-2026 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 ! 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 ! COAP_WITH_LIBTINYDTLS && ! COAP_WITH_LIBOPENSSL && ! COAP_WITH_LIBWOLFSSL && ! COAP_WITH_LIBGNUTLS && ! 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
123int
127
128#if COAP_CLIENT_SUPPORT
129int
130coap_dtls_context_set_cpsk(coap_context_t *ctx COAP_UNUSED,
131 coap_dtls_cpsk_t *setup_data COAP_UNUSED
132 ) {
133 return 0;
134}
135#endif /* COAP_CLIENT_SUPPORT */
136
137#if COAP_SERVER_SUPPORT
138int
139coap_dtls_context_set_spsk(coap_context_t *ctx COAP_UNUSED,
140 coap_dtls_spsk_t *setup_data COAP_UNUSED
141 ) {
142 return 0;
143}
144#endif /* COAP_SERVER_SUPPORT */
145
146int
150
152
153void
155}
156
157void *
159 coap_tls_library_t *tls_lib) {
160 if (tls_lib)
161 *tls_lib = COAP_TLS_LIBRARY_NOTLS;
162 return NULL;
163}
164
165void
169
170void
173
174void
178
183
184void *
186 return NULL;
187}
188
189void
192
193#if COAP_SERVER_SUPPORT
194void *
195coap_dtls_new_server_session(coap_session_t *session COAP_UNUSED) {
196 return NULL;
197}
198#endif /* COAP_SERVER_SUPPORT */
199
200#if COAP_CLIENT_SUPPORT
201void *
202coap_dtls_new_client_session(coap_session_t *session COAP_UNUSED) {
203 return NULL;
204}
205#endif /* COAP_CLIENT_SUPPORT */
206
207void
210
211void
214
215ssize_t
217 const uint8_t *data COAP_UNUSED,
218 size_t data_len COAP_UNUSED) {
219 return -1;
220}
221
222int
224 return 1;
225}
226
229 return 0;
230}
231
236
237/*
238 * return 1 timed out
239 * 0 still timing out
240 */
241int
245
246int
248 const uint8_t *data COAP_UNUSED,
249 size_t data_len COAP_UNUSED
250 ) {
251 return -1;
252}
253
254#if COAP_SERVER_SUPPORT
255int
256coap_dtls_hello(coap_session_t *session COAP_UNUSED,
257 const uint8_t *data COAP_UNUSED,
258 size_t data_len COAP_UNUSED
259 ) {
260 return 0;
261}
262#endif /* COAP_SERVER_SUPPORT */
263
264unsigned int
266 return 0;
267}
268
269#if COAP_CLIENT_SUPPORT
270void *
271coap_tls_new_client_session(coap_session_t *session COAP_UNUSED) {
272 return NULL;
273}
274#endif /* COAP_CLIENT_SUPPORT */
275
276#if COAP_SERVER_SUPPORT
277void *
278coap_tls_new_server_session(coap_session_t *session COAP_UNUSED) {
279 return NULL;
280}
281#endif /* COAP_SERVER_SUPPORT */
282
283void
286
287/*
288 * strm
289 * return +ve Number of bytes written.
290 * -1 Error (error in errno).
291 */
292ssize_t
294 const uint8_t *data COAP_UNUSED,
295 size_t data_len COAP_UNUSED) {
296 return -1;
297}
298
299/*
300 * strm
301 * return >=0 Number of bytes read.
302 * -1 Error (error in errno).
303 */
304ssize_t
306 uint8_t *data COAP_UNUSED,
307 size_t data_len COAP_UNUSED) {
308 return -1;
309}
310
311#if COAP_SERVER_SUPPORT
312typedef struct coap_local_hash_t {
313 size_t ofs;
314 coap_key_t key[8]; /* 32 bytes in total */
315} coap_local_hash_t;
316
317coap_digest_ctx_t *
318coap_digest_setup(void) {
319 coap_key_t *digest_ctx = coap_malloc_type(COAP_DIGEST_CTX, sizeof(coap_local_hash_t));
320
321 if (digest_ctx) {
322 memset(digest_ctx, 0, sizeof(coap_local_hash_t));
323 }
324
325 return digest_ctx;
326}
327
328void
329coap_digest_free(coap_digest_ctx_t *digest_ctx) {
330 coap_free_type(COAP_DIGEST_CTX, digest_ctx);
331}
332
333int
334coap_digest_update(coap_digest_ctx_t *digest_ctx,
335 const uint8_t *data,
336 size_t data_len) {
337 coap_local_hash_t *local = (coap_local_hash_t *)digest_ctx;
338
339 coap_hash(data, data_len, local->key[local->ofs]);
340
341 local->ofs = (local->ofs + 1) % 7;
342 return 1;
343}
344
345int
346coap_digest_final(coap_digest_ctx_t *digest_ctx,
347 coap_digest_t *digest_buffer) {
348 coap_local_hash_t *local = (coap_local_hash_t *)digest_ctx;
349
350 memcpy(digest_buffer, local->key, sizeof(coap_digest_t));
351
352 coap_digest_free(digest_ctx);
353 return 1;
354}
355#endif /* COAP_SERVER_SUPPORT */
356
357#if COAP_WS_SUPPORT
358int
360 const coap_bin_const_t *data,
361 coap_bin_const_t **hash) {
362 SHA1Context sha1_context;
364
365 (void)alg;
366
367 SHA1Reset(&sha1_context);
368 if (SHA1Input(&sha1_context, data->s, data->length) != shaSuccess)
369 return 0;
371 if (!dummy)
372 return 0;
373 if (SHA1Result(&sha1_context, dummy->s) != shaSuccess) {
375 return 0;
376 }
377 *hash = (coap_bin_const_t *)(dummy);
378 return 1;
379}
380#endif /* COAP_WS_SUPPORT */
381
382#if COAP_OSCORE_SUPPORT
383
384int
386 return 0;
387}
388
389int
391 (void)alg;
392 return 0;
393}
394
395int
397 (void)hkdf_alg;
398 return 0;
399}
400
401int
403 coap_bin_const_t *data,
404 coap_bin_const_t *aad,
405 uint8_t *result,
406 size_t *max_result_len) {
407 (void)params;
408 (void)data;
409 (void)aad;
410 (void)result;
411 *max_result_len = 0;
412 return 0;
413}
414
415int
417 coap_bin_const_t *data,
418 coap_bin_const_t *aad,
419 uint8_t *result,
420 size_t *max_result_len) {
421 (void)params;
422 (void)data;
423 (void)aad;
424 (void)result;
425 *max_result_len = 0;
426 return 0;
427}
428
429int
431 coap_bin_const_t *key,
432 coap_bin_const_t *data,
433 coap_bin_const_t **hmac) {
434 (void)hmac_alg;
435 (void)key;
436 (void)data;
437 (void)hmac;
438 return 0;
439}
440
441#endif /* COAP_OSCORE_SUPPORT */
442
443#else /* !COAP_WITH_LIBTINYDTLS && !COAP_WITH_LIBOPENSSL && !COAP_WITH_LIBWOLFSSL && !COAP_WITH_LIBGNUTLS */
444
445#ifdef __clang__
446/* Make compilers happy that do not like empty modules. As this function is
447 * never used, we ignore -Wunused-function at the end of compiling this file
448 */
449#pragma GCC diagnostic ignored "-Wunused-function"
450#endif
451static inline void
452dummy(void) {
453}
454
455#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:52
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:233
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:305
coap_tick_t coap_dtls_get_context_timeout(void *dtls_context COAP_UNUSED)
Definition coap_notls.c:228
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:247
void * coap_dtls_get_tls(const coap_session_t *c_session COAP_UNUSED, coap_tls_library_t *tls_lib)
Definition coap_notls.c:158
unsigned int coap_dtls_get_overhead(coap_session_t *session COAP_UNUSED)
Definition coap_notls.c:265
int coap_dtls_context_load_pki_trust_store(coap_context_t *ctx COAP_UNUSED)
Definition coap_notls.c:124
static coap_log_t dtls_log_level
Definition coap_notls.c:151
int coap_dtls_context_check_keys_enabled(coap_context_t *ctx COAP_UNUSED)
Definition coap_notls.c:147
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:216
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:293
void coap_dtls_session_update_mtu(coap_session_t *session COAP_UNUSED)
Definition coap_notls.c:212
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:242
void coap_dtls_free_context(void *handle COAP_UNUSED)
Definition coap_notls.c:190
void coap_dtls_free_session(coap_session_t *coap_session COAP_UNUSED)
Definition coap_notls.c:208
void * coap_dtls_new_context(coap_context_t *coap_context COAP_UNUSED)
Definition coap_notls.c:185
void coap_tls_free_session(coap_session_t *coap_session COAP_UNUSED)
Definition coap_notls.c:284
#define NULL
Definition coap_option.h:30
int SHA1Result(SHA1Context *, uint8_t Message_Digest[SHA1HashSize])
int SHA1Reset(SHA1Context *)
int SHA1Input(SHA1Context *, const uint8_t *, unsigned int)
@ shaSuccess
#define SHA1HashSize
uint64_t coap_tick_t
This data type represents internal timer ticks with COAP_TICKS_PER_SECOND resolution.
Definition coap_time.h:149
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_dtls_startup(void)
Initialize the underlying (D)TLS Library layer.
Definition coap_notls.c:154
void coap_dtls_thread_shutdown(void)
Close down the underlying (D)TLS Library layer.
Definition coap_notls.c:171
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:223
void coap_dtls_shutdown(void)
Close down the underlying (D)TLS Library layer.
Definition coap_notls.c:166
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:48
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:74
@ COAP_TLS_LIBRARY_NOTLS
No DTLS library.
Definition coap_dtls.h:75
coap_log_t
Logging type.
Definition coap_debug.h:56
coap_log_t coap_dtls_get_log_level(void)
Get the current (D)TLS logging.
Definition coap_notls.c:180
void coap_dtls_set_log_level(coap_log_t level)
Sets the (D)TLS logging level to the specified level.
Definition coap_notls.c:175
@ COAP_LOG_EMERG
Definition coap_debug.h:57
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:81
void coap_delete_binary(coap_binary_t *s)
Deletes the given coap_binary_t object and releases any memory allocated.
Definition coap_str.c:114
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:74
CoAP binary data definition with const data.
Definition coap_str.h:65
size_t length
length of binary data
Definition coap_str.h:66
const uint8_t * s
read-only binary data
Definition coap_str.h:67
CoAP binary data definition.
Definition coap_str.h:57
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:414
The structure used for defining the PKI setup data to be used.
Definition coap_dtls.h:316
The structure used for defining the Server PSK setup data to be used.
Definition coap_dtls.h:505
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
The structure used for returning the underlying (D)TLS library information.
Definition coap_dtls.h:87
coap_tls_library_t type
Library type.
Definition coap_dtls.h:89
uint64_t version
(D)TLS runtime Library Version
Definition coap_dtls.h:88