libcoap 4.3.4
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-2023 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
18#include "coap3/coap_internal.h"
19
20#if !defined(COAP_WITH_LIBTINYDTLS) && !defined(COAP_WITH_LIBOPENSSL) && !defined(COAP_WITH_LIBGNUTLS) && !defined(COAP_WITH_LIBMBEDTLS)
21
22int
24 return 0;
25}
26
27int
29 return 0;
30}
31
32/*
33 * return 0 failed
34 * 1 passed
35 */
36int
38 return 0;
39}
40
41/*
42 * return 0 failed
43 * 1 passed
44 */
45int
47 return 0;
48}
49
50/*
51 * return 0 failed
52 * 1 passed
53 */
54int
56 return 0;
57}
58
59/*
60 * return 0 failed
61 * 1 passed
62 */
63int
65 return 0;
66}
67
70 static coap_tls_version_t version;
71 version.version = 0;
73 return &version;
74}
75
76int
78 const coap_dtls_pki_t *setup_data COAP_UNUSED,
80 ) {
81 return 0;
82}
83
84int
86 const char *ca_file COAP_UNUSED,
87 const char *ca_path COAP_UNUSED
88 ) {
89 return 0;
90}
91
92#if COAP_CLIENT_SUPPORT
93int
96 ) {
97 return 0;
98}
99#endif /* COAP_CLIENT_SUPPORT */
100
101#if COAP_SERVER_SUPPORT
102int
104 coap_dtls_spsk_t *setup_data COAP_UNUSED
105 ) {
106 return 0;
107}
108#endif /* COAP_SERVER_SUPPORT */
109
110int
112 return 0;
113}
114
116
117void
119}
120
121void *
123 coap_tls_library_t *tls_lib) {
124 if (tls_lib)
125 *tls_lib = COAP_TLS_LIBRARY_NOTLS;
126 return NULL;
127}
128
129void
132}
133
134void
136 dtls_log_level = level;
137}
138
141 return dtls_log_level;
142}
143
144void *
146 return NULL;
147}
148
149void
151}
152
153#if COAP_SERVER_SUPPORT
154void *
156 return NULL;
157}
158#endif /* COAP_SERVER_SUPPORT */
159
160#if COAP_CLIENT_SUPPORT
161void *
163 return NULL;
164}
165#endif /* COAP_CLIENT_SUPPORT */
166
167void
169}
170
171void
173}
174
175ssize_t
177 const uint8_t *data COAP_UNUSED,
178 size_t data_len COAP_UNUSED) {
179 return -1;
180}
181
182int
184 return 1;
185}
186
189 return 0;
190}
191
194 return 0;
195}
196
197/*
198 * return 1 timed out
199 * 0 still timing out
200 */
201int
203 return 0;
204}
205
206int
208 const uint8_t *data COAP_UNUSED,
209 size_t data_len COAP_UNUSED
210 ) {
211 return -1;
212}
213
214#if COAP_SERVER_SUPPORT
215int
217 const uint8_t *data COAP_UNUSED,
218 size_t data_len COAP_UNUSED
219 ) {
220 return 0;
221}
222#endif /* COAP_SERVER_SUPPORT */
223
224unsigned int
226 return 0;
227}
228
229#if COAP_CLIENT_SUPPORT
230void *
232 return NULL;
233}
234#endif /* COAP_CLIENT_SUPPORT */
235
236#if COAP_SERVER_SUPPORT
237void *
239 return NULL;
240}
241#endif /* COAP_SERVER_SUPPORT */
242
243void
245}
246
247/*
248 * strm
249 * return +ve Number of bytes written.
250 * -1 Error (error in errno).
251 */
252ssize_t
254 const uint8_t *data COAP_UNUSED,
255 size_t data_len COAP_UNUSED) {
256 return -1;
257}
258
259/*
260 * strm
261 * return >=0 Number of bytes read.
262 * -1 Error (error in errno).
263 */
264ssize_t
266 uint8_t *data COAP_UNUSED,
267 size_t data_len COAP_UNUSED) {
268 return -1;
269}
270
271#if COAP_SERVER_SUPPORT
272typedef struct coap_local_hash_t {
273 size_t ofs;
274 coap_key_t key[8]; /* 32 bytes in total */
275} coap_local_hash_t;
276
278coap_digest_setup(void) {
279 coap_key_t *digest_ctx = coap_malloc_type(COAP_DIGEST_CTX, sizeof(coap_local_hash_t));
280
281 if (digest_ctx) {
282 memset(digest_ctx, 0, sizeof(coap_local_hash_t));
283 }
284
285 return digest_ctx;
286}
287
288void
290 coap_free_type(COAP_DIGEST_CTX, digest_ctx);
291}
292
293int
295 const uint8_t *data,
296 size_t data_len) {
297 coap_local_hash_t *local = (coap_local_hash_t *)digest_ctx;
298
299 coap_hash(data, data_len, local->key[local->ofs]);
300
301 local->ofs = (local->ofs + 1) % 7;
302 return 1;
303}
304
305int
307 coap_digest_t *digest_buffer) {
308 coap_local_hash_t *local = (coap_local_hash_t *)digest_ctx;
309
310 memcpy(digest_buffer, local->key, sizeof(coap_digest_t));
311
312 coap_digest_free(digest_ctx);
313 return 1;
314}
315#endif /* COAP_SERVER_SUPPORT */
316
317#if COAP_WS_SUPPORT
318int
320 const coap_bin_const_t *data,
321 coap_bin_const_t **hash) {
322 (void)alg;
323 (void)data;
324 (void)hash;
325 return 0;
326}
327#endif /* COAP_WS_SUPPORT */
328
329#if COAP_OSCORE_SUPPORT
330
331int
333 return 0;
334}
335
336int
338 (void)alg;
339 return 0;
340}
341
342int
344 (void)hkdf_alg;
345 return 0;
346}
347
348int
350 coap_bin_const_t *data,
351 coap_bin_const_t *aad,
352 uint8_t *result,
353 size_t *max_result_len) {
354 (void)params;
355 (void)data;
356 (void)aad;
357 (void)result;
358 *max_result_len = 0;
359 return 0;
360}
361
362int
364 coap_bin_const_t *data,
365 coap_bin_const_t *aad,
366 uint8_t *result,
367 size_t *max_result_len) {
368 (void)params;
369 (void)data;
370 (void)aad;
371 (void)result;
372 *max_result_len = 0;
373 return 0;
374}
375
376int
378 coap_bin_const_t *key,
379 coap_bin_const_t *data,
380 coap_bin_const_t **hmac) {
381 (void)hmac_alg;
382 (void)key;
383 (void)data;
384 (void)hmac;
385 return 0;
386}
387
388#endif /* COAP_OSCORE_SUPPORT */
389
390#else /* !COAP_WITH_LIBTINYDTLS && !COAP_WITH_LIBOPENSSL && !COAP_WITH_LIBGNUTLS */
391
392#ifdef __clang__
393/* Make compilers happy that do not like empty modules. As this function is
394 * never used, we ignore -Wunused-function at the end of compiling this file
395 */
396#pragma GCC diagnostic ignored "-Wunused-function"
397#endif
398static inline void
399dummy(void) {
400}
401
402#endif /* !COAP_WITH_LIBTINYDTLS && !COAP_WITH_LIBOPENSSL && !COAP_WITH_LIBGNUTLS && !COAP_WITH_LIBMBEDTLS */
unsigned char coap_key_t[4]
#define coap_hash(String, Length, Result)
Pulls together all the internal only header files.
@ COAP_DIGEST_CTX
Definition: coap_mem.h:57
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:77
coap_tick_t coap_dtls_get_timeout(coap_session_t *session COAP_UNUSED, coap_tick_t now COAP_UNUSED)
Definition: coap_notls.c:193
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:265
coap_tick_t coap_dtls_get_context_timeout(void *dtls_context COAP_UNUSED)
Definition: coap_notls.c:188
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:207
void * coap_dtls_get_tls(const coap_session_t *c_session COAP_UNUSED, coap_tls_library_t *tls_lib)
Definition: coap_notls.c:122
unsigned int coap_dtls_get_overhead(coap_session_t *session COAP_UNUSED)
Definition: coap_notls.c:225
static coap_log_t dtls_log_level
Definition: coap_notls.c:115
int coap_dtls_context_check_keys_enabled(coap_context_t *ctx COAP_UNUSED)
Definition: coap_notls.c:111
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:176
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:253
void coap_dtls_session_update_mtu(coap_session_t *session COAP_UNUSED)
Definition: coap_notls.c:172
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:85
int coap_dtls_handle_timeout(coap_session_t *session COAP_UNUSED)
Definition: coap_notls.c:202
void coap_dtls_free_context(void *handle COAP_UNUSED)
Definition: coap_notls.c:150
void coap_dtls_free_session(coap_session_t *coap_session COAP_UNUSED)
Definition: coap_notls.c:168
void * coap_dtls_new_context(coap_context_t *coap_context COAP_UNUSED)
Definition: coap_notls.c:145
void coap_tls_free_session(coap_session_t *coap_session COAP_UNUSED)
Definition: coap_notls.c:244
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:144
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:118
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_is_context_timeout(void)
Check if timeout is handled per CoAP session or per CoAP context.
Definition: coap_notls.c:183
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:130
void * coap_tls_new_client_session(coap_session_t *coap_session)
Create a new TLS client-side session.
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:69
int coap_dtls_psk_is_supported(void)
Check whether (D)TLS PSK is available.
Definition: coap_notls.c:37
coap_dtls_role_t
Definition: coap_dtls.h:43
int coap_tls_is_supported(void)
Check whether TLS is available.
Definition: coap_notls.c:28
int coap_dtls_is_supported(void)
Check whether DTLS is available.
Definition: coap_notls.c:23
int coap_dtls_pki_is_supported(void)
Check whether (D)TLS PKI is available.
Definition: coap_notls.c:46
int coap_dtls_rpk_is_supported(void)
Check whether (D)TLS RPK is available.
Definition: coap_notls.c:64
coap_tls_library_t
Definition: coap_dtls.h:92
int coap_dtls_pkcs11_is_supported(void)
Check whether (D)TLS PKCS11 is available.
Definition: coap_notls.c:55
@ COAP_TLS_LIBRARY_NOTLS
No DTLS library.
Definition: coap_dtls.h:93
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:140
void coap_dtls_set_log_level(coap_log_t level)
Sets the (D)TLS logging level to the specified level.
Definition: coap_notls.c:135
@ 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
int coap_oscore_is_supported(void)
Check whether OSCORE is available.
Definition: coap_oscore.c:2104
#define COAP_UNUSED
Definition: libcoap.h:68
CoAP binary data definition with const data.
Definition: coap_str.h:64
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:378
The structure used for defining the PKI setup data to be used.
Definition: coap_dtls.h:284
The structure used for defining the Server PSK setup data to be used.
Definition: coap_dtls.h:465
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...
The structure used for returning the underlying (D)TLS library information.
Definition: coap_dtls.h:104
coap_tls_library_t type
Library type.
Definition: coap_dtls.h:106
uint64_t version
(D)TLS runtime Library Version
Definition: coap_dtls.h:105