libcoap 4.3.5-develop-5347a62
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
17
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 && ! COAP_WITH_LIBOPENHITLS
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
99#if ! COAP_WITH_LIBMBEDTLS_OSCORE && ! COAP_WITH_LIBOPENHITLS_OSCORE
102 static coap_tls_version_t version;
103 version.version = 0;
105 return &version;
106}
107
108void
110}
111
112void
116
117void
120
121#if COAP_WS_SUPPORT
122int
124 const coap_bin_const_t *data,
125 coap_bin_const_t **hash) {
126 SHA1Context sha1_context;
128
129 (void)alg;
130
131 SHA1Reset(&sha1_context);
132 if (SHA1Input(&sha1_context, data->s, data->length) != shaSuccess)
133 return 0;
135 if (!dummy)
136 return 0;
137 if (SHA1Result(&sha1_context, dummy->s) != shaSuccess) {
139 return 0;
140 }
141 *hash = (coap_bin_const_t *)(dummy);
142 return 1;
143}
144#endif /* COAP_WS_SUPPORT */
145
146#if COAP_OSCORE_SUPPORT
147
148int
150 return 0;
151}
152
153int
155 return 0;
156}
157
158int
160 return 0;
161}
162
163int
165 (void)alg;
166 return 0;
167}
168
169int
171 (void)hkdf_alg;
172 return 0;
173}
174
175int
177 coap_bin_const_t *data,
178 coap_bin_const_t *aad,
179 uint8_t *result,
180 size_t *max_result_len) {
181 (void)params;
182 (void)data;
183 (void)aad;
184 (void)result;
185 *max_result_len = 0;
186 return 0;
187}
188
189int
191 coap_bin_const_t *data,
192 coap_bin_const_t *aad,
193 uint8_t *result,
194 size_t *max_result_len) {
195 (void)params;
196 (void)data;
197 (void)aad;
198 (void)result;
199 *max_result_len = 0;
200 return 0;
201}
202
203int
205 coap_bin_const_t *key,
206 coap_bin_const_t *data,
207 coap_bin_const_t **hmac) {
208 (void)hmac_alg;
209 (void)key;
210 (void)data;
211 (void)hmac;
212 return 0;
213}
214
215#endif /* COAP_OSCORE_SUPPORT */
216
217#if COAP_OSCORE_GROUP_SUPPORT
218int
219coap_crypto_check_curve_alg(cose_curve_t alg) {
220 (void)alg;
221 return 0;
222}
223
224int
225coap_crypto_read_pem_private_key(const char *filename,
226 coap_crypto_pri_key_t **private) {
227 (void)filename;
228 (void)private;
229 return 0;
230}
231
232int
233coap_crypto_read_asn1_private_key(coap_bin_const_t *binary,
234 coap_crypto_pri_key_t **private) {
235 (void)private;
236
237 coap_delete_bin_const(binary);
238 return 0;
239}
240
241int
242coap_crypto_read_raw_private_key(cose_curve_t curve,
243 coap_bin_const_t *binary,
244 coap_crypto_pri_key_t **private) {
245 (void)curve;
246 (void)private;
247
248 coap_delete_bin_const(binary);
249 return 0;
250}
251
253coap_crypto_duplicate_private_key(coap_crypto_pri_key_t *key) {
254 (void)key;
255 return NULL;
256}
257
258void
259coap_crypto_delete_private_key(coap_crypto_pri_key_t *key) {
260 (void)key;
261}
262
263int
264coap_crypto_read_pem_public_cred(const char *filename,
265 coap_crypto_cred_t **public) {
266 (void)filename;
267 (void)public;
268 return 0;
269}
270
271int
272coap_crypto_read_asn1_public_cred(coap_bin_const_t *binary,
273 coap_crypto_cred_t **public) {
274 (void)public;
275
276 coap_delete_bin_const(binary);
277 return 0;
278}
279
280int
281coap_crypto_read_raw_public_cred(cose_curve_t curve,
282 coap_bin_const_t *binary,
283 coap_crypto_cred_t **public) {
284 (void)curve;
285 (void)public;
286
287 coap_delete_bin_const(binary);
288 return 0;
289}
290
292coap_crypto_duplicate_public_cred(coap_crypto_cred_t *key) {
293 (void)key;
294 return NULL;
295}
296
297void
298coap_crypto_delete_public_cred(coap_crypto_cred_t *key) {
299 (void)key;
300}
301
302int
303coap_crypto_hash_sign(cose_alg_t hash,
304 coap_binary_t *signature,
305 coap_bin_const_t *text,
306 coap_crypto_pri_key_t *private_key) {
307 (void)hash;
308 (void)signature;
309 (void)text;
310 (void)private_key;
311 return 0;
312}
313
314int
315coap_crypto_hash_verify(cose_alg_t hash,
316 coap_binary_t *signature,
317 coap_bin_const_t *text,
318 coap_crypto_cred_t *public_cred) {
319 (void)hash;
320 (void)signature;
321 (void)text;
322 (void)public_cred;
323 return 0;
324}
325
326int
327coap_crypto_gen_pkey(cose_curve_t curve,
328 coap_bin_const_t **private,
329 coap_bin_const_t **public) {
330 (void)curve;
331 (void)private;
332 (void)public;
333 return 0;
334}
335
336int
337coap_crypto_derive_shared_secret(cose_alg_t alg_pairwise,
338 coap_bin_const_t *raw_local_private,
339 coap_bin_const_t *raw_peer_public,
340 coap_bin_const_t **shared_secret) {
341 (void)alg_pairwise;
342 (void)raw_local_private;
343 (void)raw_peer_public;
344 (void)shared_secret;
345 return 0;
346}
347
348#endif /* COAP_OSCORE_GROUP_SUPPORT */
349
350#if COAP_SERVER_SUPPORT
351coap_digest_ctx_t *
352coap_digest_setup(void) {
354
355 if (digest_ctx) {
356 SHA1Reset(digest_ctx);
357 }
358
359 return digest_ctx;
360}
361
362void
363coap_digest_free(coap_digest_ctx_t *digest_ctx) {
364 coap_free_type(COAP_DIGEST_CTX, digest_ctx);
365}
366
367int
368coap_digest_update(coap_digest_ctx_t *digest_ctx,
369 const uint8_t *data,
370 size_t data_len) {
371 if (SHA1Input(digest_ctx, data, data_len) != shaSuccess)
372 return 0;
373 return 1;
374}
375
376int
377coap_digest_final(coap_digest_ctx_t *digest_ctx,
378 coap_digest_t *digest_buffer) {
379 int ret = 1;
380
381 memset(digest_buffer, 0, sizeof(coap_digest_t));
382 if (SHA1Result(digest_ctx, (uint8_t *)digest_buffer) != shaSuccess) {
383 ret = 0;
384 }
385 coap_digest_free(digest_ctx);
386 return ret;
387}
388#endif /* COAP_SERVER_SUPPORT */
389
390#endif /* ! COAP_WITH_LIBMBEDTLS_OSCORE && ! COAP_WITH_LIBOPENHITLS_OSCORE */
391
392/* (D)TLS specific functions */
393
394int
396 const coap_dtls_pki_t *setup_data COAP_UNUSED,
398 ) {
399 return 0;
400}
401
402int
404 const char *ca_file COAP_UNUSED,
405 const char *ca_path COAP_UNUSED
406 ) {
407 return 0;
408}
409
410int
414
415#if COAP_CLIENT_SUPPORT
416int
417coap_dtls_context_set_cpsk(coap_context_t *ctx COAP_UNUSED,
418 coap_dtls_cpsk_t *setup_data COAP_UNUSED
419 ) {
420 return 0;
421}
422#endif /* COAP_CLIENT_SUPPORT */
423
424#if COAP_SERVER_SUPPORT
425int
426coap_dtls_context_set_spsk(coap_context_t *ctx COAP_UNUSED,
427 coap_dtls_spsk_t *setup_data COAP_UNUSED
428 ) {
429 return 0;
430}
431#endif /* COAP_SERVER_SUPPORT */
432
433int
437
439
440void *
442 coap_tls_library_t *tls_lib) {
443 if (tls_lib)
444 *tls_lib = COAP_TLS_LIBRARY_NOTLS;
445 return NULL;
446}
447
448void
452
457
458void *
460 return NULL;
461}
462
463void
466
467#if COAP_SERVER_SUPPORT
468void *
469coap_dtls_new_server_session(coap_session_t *session COAP_UNUSED) {
470 return NULL;
471}
472#endif /* COAP_SERVER_SUPPORT */
473
474#if COAP_CLIENT_SUPPORT
475void *
476coap_dtls_new_client_session(coap_session_t *session COAP_UNUSED) {
477 return NULL;
478}
479#endif /* COAP_CLIENT_SUPPORT */
480
481void
484
485void
488
489ssize_t
491 const uint8_t *data COAP_UNUSED,
492 size_t data_len COAP_UNUSED) {
493 return -1;
494}
495
496int
498 return 1;
499}
500
503 return 0;
504}
505
510
511/*
512 * return 1 timed out
513 * 0 still timing out
514 */
515int
519
520int
522 const uint8_t *data COAP_UNUSED,
523 size_t data_len COAP_UNUSED
524 ) {
525 return -1;
526}
527
528#if COAP_SERVER_SUPPORT
529int
530coap_dtls_hello(coap_session_t *session COAP_UNUSED,
531 const uint8_t *data COAP_UNUSED,
532 size_t data_len COAP_UNUSED
533 ) {
534 return 0;
535}
536#endif /* COAP_SERVER_SUPPORT */
537
538unsigned int
540 return 0;
541}
542
543#if COAP_CLIENT_SUPPORT
544void *
545coap_tls_new_client_session(coap_session_t *session COAP_UNUSED) {
546 return NULL;
547}
548#endif /* COAP_CLIENT_SUPPORT */
549
550#if COAP_SERVER_SUPPORT
551void *
552coap_tls_new_server_session(coap_session_t *session COAP_UNUSED) {
553 return NULL;
554}
555#endif /* COAP_SERVER_SUPPORT */
556
557void
560
561/*
562 * strm
563 * return +ve Number of bytes written.
564 * -1 Error (error in errno).
565 */
566ssize_t
568 const uint8_t *data COAP_UNUSED,
569 size_t data_len COAP_UNUSED) {
570 return -1;
571}
572
573/*
574 * strm
575 * return >=0 Number of bytes read.
576 * -1 Error (error in errno).
577 */
578ssize_t
580 uint8_t *data COAP_UNUSED,
581 size_t data_len COAP_UNUSED) {
582 return -1;
583}
584
585#else /* !COAP_WITH_LIBTINYDTLS && !COAP_WITH_LIBOPENSSL && !COAP_WITH_LIBWOLFSSL && !COAP_WITH_LIBGNUTLS */
586
587#ifdef __clang__
588/* Make compilers happy that do not like empty modules. As this function is
589 * never used, we ignore -Wunused-function at the end of compiling this file
590 */
591#pragma GCC diagnostic ignored "-Wunused-function"
592#endif
593static inline void
594dummy(void) {
595}
596
597#endif /* !COAP_WITH_LIBTINYDTLS && !COAP_WITH_LIBOPENSSL && !COAP_WITH_LIBWOLFSSL && !COAP_WITH_LIBGNUTLS && !COAP_WITH_LIBMBEDTLS */
static void dummy(void)
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:395
coap_tick_t coap_dtls_get_timeout(coap_session_t *session COAP_UNUSED, coap_tick_t now COAP_UNUSED)
Definition coap_notls.c:507
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:579
coap_tick_t coap_dtls_get_context_timeout(void *dtls_context COAP_UNUSED)
Definition coap_notls.c:502
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:521
void * coap_dtls_get_tls(const coap_session_t *c_session COAP_UNUSED, coap_tls_library_t *tls_lib)
Definition coap_notls.c:441
unsigned int coap_dtls_get_overhead(coap_session_t *session COAP_UNUSED)
Definition coap_notls.c:539
int coap_dtls_context_load_pki_trust_store(coap_context_t *ctx COAP_UNUSED)
Definition coap_notls.c:411
static coap_log_t dtls_log_level
Definition coap_notls.c:438
int coap_dtls_context_check_keys_enabled(coap_context_t *ctx COAP_UNUSED)
Definition coap_notls.c:434
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:490
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:567
void coap_dtls_session_update_mtu(coap_session_t *session COAP_UNUSED)
Definition coap_notls.c:486
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:403
int coap_dtls_handle_timeout(coap_session_t *session COAP_UNUSED)
Definition coap_notls.c:516
void coap_dtls_free_context(void *handle COAP_UNUSED)
Definition coap_notls.c:464
void coap_dtls_free_session(coap_session_t *coap_session COAP_UNUSED)
Definition coap_notls.c:482
void * coap_dtls_new_context(coap_context_t *coap_context COAP_UNUSED)
Definition coap_notls.c:459
void coap_tls_free_session(coap_session_t *coap_session COAP_UNUSED)
Definition coap_notls.c:558
#define NULL
Definition coap_option.h:30
int SHA1Reset(SHA1Context *context)
Definition coap_sha1.c:100
int SHA1Input(SHA1Context *context, const uint8_t *message_array, unsigned length)
Definition coap_sha1.c:193
int SHA1Result(SHA1Context *context, uint8_t Message_Digest[SHA1HashSize])
Definition coap_sha1.c:141
@ 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:109
void coap_dtls_thread_shutdown(void)
Close down the underlying (D)TLS Library layer.
Definition coap_notls.c:118
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:497
void coap_dtls_shutdown(void)
Close down the underlying (D)TLS Library layer.
Definition coap_notls.c:113
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:101
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:454
void coap_dtls_set_log_level(coap_log_t level)
Sets the (D)TLS logging level to the specified level.
Definition coap_notls.c:449
@ COAP_LOG_EMERG
Definition coap_debug.h:57
cose_hkdf_alg_t
cose_hmac_alg_t
cose_curve_t
Definition oscore_cose.h:62
cose_alg_t
void coap_delete_bin_const(coap_bin_const_t *s)
Deletes the given const binary data and releases any memory allocated.
Definition coap_str.c:130
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_group_is_supported(void)
Check whether OSCORE Group support is available.
int coap_oscore_pairwise_is_supported(void)
Check whether OSCORE Pairwise support is available.
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.
Holds credential definitions.
The common structure that holds the Crypto information.
Holds private key definitions.
The structure used for defining the Client PSK setup data to be used.
Definition coap_dtls.h:418
The structure used for defining the PKI setup data to be used.
Definition coap_dtls.h:317
The structure used for defining the Server PSK setup data to be used.
Definition coap_dtls.h:509
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:88
coap_tls_library_t type
Library type.
Definition coap_dtls.h:90
uint64_t version
(D)TLS runtime Library Version
Definition coap_dtls.h:89