libcoap 4.3.3
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
131}
132
133void
135 dtls_log_level = level;
136}
137
140 return dtls_log_level;
141}
142
143void *
145 return NULL;
146}
147
148void
150}
151
152#if COAP_SERVER_SUPPORT
153void *
155 return NULL;
156}
157#endif /* COAP_SERVER_SUPPORT */
158
159#if COAP_CLIENT_SUPPORT
160void *
162 return NULL;
163}
164#endif /* COAP_CLIENT_SUPPORT */
165
166void
168}
169
170void
172}
173
174ssize_t
176 const uint8_t *data COAP_UNUSED,
177 size_t data_len COAP_UNUSED) {
178 return -1;
179}
180
181int
183 return 1;
184}
185
188 return 0;
189}
190
193 return 0;
194}
195
196/*
197 * return 1 timed out
198 * 0 still timing out
199 */
200int
202 return 0;
203}
204
205int
207 const uint8_t *data COAP_UNUSED,
208 size_t data_len COAP_UNUSED
209 ) {
210 return -1;
211}
212
213#if COAP_SERVER_SUPPORT
214int
216 const uint8_t *data COAP_UNUSED,
217 size_t data_len COAP_UNUSED
218 ) {
219 return 0;
220}
221#endif /* COAP_SERVER_SUPPORT */
222
223unsigned int
225 return 0;
226}
227
228#if COAP_CLIENT_SUPPORT
229void *
231 return NULL;
232}
233#endif /* COAP_CLIENT_SUPPORT */
234
235#if COAP_SERVER_SUPPORT
236void *
238 return NULL;
239}
240#endif /* COAP_SERVER_SUPPORT */
241
242void
244}
245
246/*
247 * strm
248 * return +ve Number of bytes written.
249 * -1 Error (error in errno).
250 */
251ssize_t
253 const uint8_t *data COAP_UNUSED,
254 size_t data_len COAP_UNUSED) {
255 return -1;
256}
257
258/*
259 * strm
260 * return >=0 Number of bytes read.
261 * -1 Error (error in errno).
262 */
263ssize_t
265 uint8_t *data COAP_UNUSED,
266 size_t data_len COAP_UNUSED) {
267 return -1;
268}
269
270#if COAP_SERVER_SUPPORT
271typedef struct coap_local_hash_t {
272 size_t ofs;
273 coap_key_t key[8]; /* 32 bytes in total */
274} coap_local_hash_t;
275
277coap_digest_setup(void) {
278 coap_key_t *digest_ctx = coap_malloc_type(COAP_DIGEST_CTX, sizeof(coap_local_hash_t));
279
280 if (digest_ctx) {
281 memset(digest_ctx, 0, sizeof(coap_local_hash_t));
282 }
283
284 return digest_ctx;
285}
286
287void
289 coap_free_type(COAP_DIGEST_CTX, digest_ctx);
290}
291
292int
294 const uint8_t *data,
295 size_t data_len) {
296 coap_local_hash_t *local = (coap_local_hash_t *)digest_ctx;
297
298 coap_hash(data, data_len, local->key[local->ofs]);
299
300 local->ofs = (local->ofs + 1) % 7;
301 return 1;
302}
303
304int
306 coap_digest_t *digest_buffer) {
307 coap_local_hash_t *local = (coap_local_hash_t *)digest_ctx;
308
309 memcpy(digest_buffer, local->key, sizeof(coap_digest_t));
310
311 coap_digest_free(digest_ctx);
312 return 1;
313}
314#endif /* COAP_SERVER_SUPPORT */
315
316#if COAP_WS_SUPPORT
317int
319 const coap_bin_const_t *data,
320 coap_bin_const_t **hash) {
321 (void)alg;
322 (void)data;
323 (void)hash;
324 return 0;
325}
326#endif /* COAP_WS_SUPPORT */
327
328#if COAP_OSCORE_SUPPORT
329
330int
332 return 0;
333}
334
335int
337 (void)alg;
338 return 0;
339}
340
341int
343 (void)hkdf_alg;
344 return 0;
345}
346
347int
349 coap_bin_const_t *data,
350 coap_bin_const_t *aad,
351 uint8_t *result,
352 size_t *max_result_len) {
353 (void)params;
354 (void)data;
355 (void)aad;
356 (void)result;
357 *max_result_len = 0;
358 return 0;
359}
360
361int
363 coap_bin_const_t *data,
364 coap_bin_const_t *aad,
365 uint8_t *result,
366 size_t *max_result_len) {
367 (void)params;
368 (void)data;
369 (void)aad;
370 (void)result;
371 *max_result_len = 0;
372 return 0;
373}
374
375int
377 coap_bin_const_t *key,
378 coap_bin_const_t *data,
379 coap_bin_const_t **hmac) {
380 (void)hmac_alg;
381 (void)key;
382 (void)data;
383 (void)hmac;
384 return 0;
385}
386
387#endif /* COAP_OSCORE_SUPPORT */
388
389#else /* !COAP_WITH_LIBTINYDTLS && !COAP_WITH_LIBOPENSSL && !COAP_WITH_LIBGNUTLS */
390
391#ifdef __clang__
392/* Make compilers happy that do not like empty modules. As this function is
393 * never used, we ignore -Wunused-function at the end of compiling this file
394 */
395#pragma GCC diagnostic ignored "-Wunused-function"
396#endif
397static inline void
398dummy(void) {
399}
400
401#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:192
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:264
coap_tick_t coap_dtls_get_context_timeout(void *dtls_context COAP_UNUSED)
Definition: coap_notls.c:187
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:206
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:224
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:175
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:252
void coap_dtls_session_update_mtu(coap_session_t *session COAP_UNUSED)
Definition: coap_notls.c:171
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:201
void coap_dtls_free_context(void *handle COAP_UNUSED)
Definition: coap_notls.c:149
void coap_dtls_free_session(coap_session_t *coap_session COAP_UNUSED)
Definition: coap_notls.c:167
void * coap_dtls_new_context(coap_context_t *coap_context COAP_UNUSED)
Definition: coap_notls.c:144
void coap_tls_free_session(coap_session_t *coap_session COAP_UNUSED)
Definition: coap_notls.c:243
COAP_STATIC_INLINE void dummy(void)
Definition: coap_time.c:139
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:182
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:139
void coap_dtls_set_log_level(coap_log_t level)
Sets the (D)TLS logging level to the specified level.
Definition: coap_notls.c:134
@ 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