libcoap 4.3.5-develop-3035cfd
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
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
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 (void)alg;
156 return 0;
157}
158
159int
161 (void)hkdf_alg;
162 return 0;
163}
164
165int
167 coap_bin_const_t *data,
168 coap_bin_const_t *aad,
169 uint8_t *result,
170 size_t *max_result_len) {
171 (void)params;
172 (void)data;
173 (void)aad;
174 (void)result;
175 *max_result_len = 0;
176 return 0;
177}
178
179int
181 coap_bin_const_t *data,
182 coap_bin_const_t *aad,
183 uint8_t *result,
184 size_t *max_result_len) {
185 (void)params;
186 (void)data;
187 (void)aad;
188 (void)result;
189 *max_result_len = 0;
190 return 0;
191}
192
193int
195 coap_bin_const_t *key,
196 coap_bin_const_t *data,
197 coap_bin_const_t **hmac) {
198 (void)hmac_alg;
199 (void)key;
200 (void)data;
201 (void)hmac;
202 return 0;
203}
204
205#endif /* COAP_OSCORE_SUPPORT */
206
207#if COAP_SERVER_SUPPORT
208typedef struct coap_local_hash_t {
209 size_t ofs;
210 coap_key_t key[8]; /* 32 bytes in total */
211} coap_local_hash_t;
212
213coap_digest_ctx_t *
214coap_digest_setup(void) {
215 coap_key_t *digest_ctx = coap_malloc_type(COAP_DIGEST_CTX, sizeof(coap_local_hash_t));
216
217 if (digest_ctx) {
218 memset(digest_ctx, 0, sizeof(coap_local_hash_t));
219 }
220
221 return digest_ctx;
222}
223
224void
225coap_digest_free(coap_digest_ctx_t *digest_ctx) {
226 coap_free_type(COAP_DIGEST_CTX, digest_ctx);
227}
228
229int
230coap_digest_update(coap_digest_ctx_t *digest_ctx,
231 const uint8_t *data,
232 size_t data_len) {
233 coap_local_hash_t *local = (coap_local_hash_t *)digest_ctx;
234
235 coap_hash(data, data_len, local->key[local->ofs]);
236
237 local->ofs = (local->ofs + 1) % 7;
238 return 1;
239}
240
241int
242coap_digest_final(coap_digest_ctx_t *digest_ctx,
243 coap_digest_t *digest_buffer) {
244 coap_local_hash_t *local = (coap_local_hash_t *)digest_ctx;
245
246 memcpy(digest_buffer, local->key, sizeof(coap_digest_t));
247
248 coap_digest_free(digest_ctx);
249 return 1;
250}
251#endif /* COAP_SERVER_SUPPORT */
252
253#endif /* ! COAP_WITH_LIBMBEDTLS_OSCORE */
254
255/* (D)TLS specific functions */
256
257int
259 const coap_dtls_pki_t *setup_data COAP_UNUSED,
261 ) {
262 return 0;
263}
264
265int
267 const char *ca_file COAP_UNUSED,
268 const char *ca_path COAP_UNUSED
269 ) {
270 return 0;
271}
272
273int
277
278#if COAP_CLIENT_SUPPORT
279int
280coap_dtls_context_set_cpsk(coap_context_t *ctx COAP_UNUSED,
281 coap_dtls_cpsk_t *setup_data COAP_UNUSED
282 ) {
283 return 0;
284}
285#endif /* COAP_CLIENT_SUPPORT */
286
287#if COAP_SERVER_SUPPORT
288int
289coap_dtls_context_set_spsk(coap_context_t *ctx COAP_UNUSED,
290 coap_dtls_spsk_t *setup_data COAP_UNUSED
291 ) {
292 return 0;
293}
294#endif /* COAP_SERVER_SUPPORT */
295
296int
300
302
303void *
305 coap_tls_library_t *tls_lib) {
306 if (tls_lib)
307 *tls_lib = COAP_TLS_LIBRARY_NOTLS;
308 return NULL;
309}
310
311void
315
320
321void *
323 return NULL;
324}
325
326void
329
330#if COAP_SERVER_SUPPORT
331void *
332coap_dtls_new_server_session(coap_session_t *session COAP_UNUSED) {
333 return NULL;
334}
335#endif /* COAP_SERVER_SUPPORT */
336
337#if COAP_CLIENT_SUPPORT
338void *
339coap_dtls_new_client_session(coap_session_t *session COAP_UNUSED) {
340 return NULL;
341}
342#endif /* COAP_CLIENT_SUPPORT */
343
344void
347
348void
351
352ssize_t
354 const uint8_t *data COAP_UNUSED,
355 size_t data_len COAP_UNUSED) {
356 return -1;
357}
358
359int
361 return 1;
362}
363
366 return 0;
367}
368
373
374/*
375 * return 1 timed out
376 * 0 still timing out
377 */
378int
382
383int
385 const uint8_t *data COAP_UNUSED,
386 size_t data_len COAP_UNUSED
387 ) {
388 return -1;
389}
390
391#if COAP_SERVER_SUPPORT
392int
393coap_dtls_hello(coap_session_t *session COAP_UNUSED,
394 const uint8_t *data COAP_UNUSED,
395 size_t data_len COAP_UNUSED
396 ) {
397 return 0;
398}
399#endif /* COAP_SERVER_SUPPORT */
400
401unsigned int
403 return 0;
404}
405
406#if COAP_CLIENT_SUPPORT
407void *
408coap_tls_new_client_session(coap_session_t *session COAP_UNUSED) {
409 return NULL;
410}
411#endif /* COAP_CLIENT_SUPPORT */
412
413#if COAP_SERVER_SUPPORT
414void *
415coap_tls_new_server_session(coap_session_t *session COAP_UNUSED) {
416 return NULL;
417}
418#endif /* COAP_SERVER_SUPPORT */
419
420void
423
424/*
425 * strm
426 * return +ve Number of bytes written.
427 * -1 Error (error in errno).
428 */
429ssize_t
431 const uint8_t *data COAP_UNUSED,
432 size_t data_len COAP_UNUSED) {
433 return -1;
434}
435
436/*
437 * strm
438 * return >=0 Number of bytes read.
439 * -1 Error (error in errno).
440 */
441ssize_t
443 uint8_t *data COAP_UNUSED,
444 size_t data_len COAP_UNUSED) {
445 return -1;
446}
447
448#else /* !COAP_WITH_LIBTINYDTLS && !COAP_WITH_LIBOPENSSL && !COAP_WITH_LIBWOLFSSL && !COAP_WITH_LIBGNUTLS */
449
450#ifdef __clang__
451/* Make compilers happy that do not like empty modules. As this function is
452 * never used, we ignore -Wunused-function at the end of compiling this file
453 */
454#pragma GCC diagnostic ignored "-Wunused-function"
455#endif
456static inline void
457dummy(void) {
458}
459
460#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:258
coap_tick_t coap_dtls_get_timeout(coap_session_t *session COAP_UNUSED, coap_tick_t now COAP_UNUSED)
Definition coap_notls.c:370
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:442
coap_tick_t coap_dtls_get_context_timeout(void *dtls_context COAP_UNUSED)
Definition coap_notls.c:365
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:384
void * coap_dtls_get_tls(const coap_session_t *c_session COAP_UNUSED, coap_tls_library_t *tls_lib)
Definition coap_notls.c:304
unsigned int coap_dtls_get_overhead(coap_session_t *session COAP_UNUSED)
Definition coap_notls.c:402
int coap_dtls_context_load_pki_trust_store(coap_context_t *ctx COAP_UNUSED)
Definition coap_notls.c:274
static coap_log_t dtls_log_level
Definition coap_notls.c:301
int coap_dtls_context_check_keys_enabled(coap_context_t *ctx COAP_UNUSED)
Definition coap_notls.c:297
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:353
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:430
void coap_dtls_session_update_mtu(coap_session_t *session COAP_UNUSED)
Definition coap_notls.c:349
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:266
int coap_dtls_handle_timeout(coap_session_t *session COAP_UNUSED)
Definition coap_notls.c:379
void coap_dtls_free_context(void *handle COAP_UNUSED)
Definition coap_notls.c:327
void coap_dtls_free_session(coap_session_t *coap_session COAP_UNUSED)
Definition coap_notls.c:345
void * coap_dtls_new_context(coap_context_t *coap_context COAP_UNUSED)
Definition coap_notls.c:322
void coap_tls_free_session(coap_session_t *coap_session COAP_UNUSED)
Definition coap_notls.c:421
#define NULL
Definition coap_option.h:30
int SHA1Result(SHA1Context *, uint8_t Message_Digest[SHA1HashSize])
@ shaSuccess
int SHA1Reset(SHA1Context *)
int SHA1Input(SHA1Context *, const uint8_t *, unsigned int)
#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:360
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:317
void coap_dtls_set_log_level(coap_log_t level)
Sets the (D)TLS logging level to the specified level.
Definition coap_notls.c:312
@ 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