libcoap 4.3.1
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-2022 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(HAVE_LIBTINYDTLS) && !defined(HAVE_OPENSSL) && !defined(HAVE_LIBGNUTLS) && !defined(HAVE_MBEDTLS)
21
22int
24 return 0;
25}
26
27int
29 return 0;
30}
31
34 static coap_tls_version_t version;
35 version.version = 0;
37 return &version;
38}
39
40int
42 const coap_dtls_pki_t* setup_data COAP_UNUSED,
44) {
45 return 0;
46}
47
48int
50 const char *ca_file COAP_UNUSED,
51 const char *ca_path COAP_UNUSED
52) {
53 return 0;
54}
55
56#if COAP_CLIENT_SUPPORT
57int
60) {
61 return 0;
62}
63#endif /* COAP_CLIENT_SUPPORT */
64
65#if COAP_SERVER_SUPPORT
66int
69) {
70 return 0;
71}
72#endif /* COAP_SERVER_SUPPORT */
73
74int
76{
77 return 0;
78}
79
80static int dtls_log_level = 0;
81
83}
84
85void *
87 coap_tls_library_t *tls_lib) {
88 if (tls_lib)
89 *tls_lib = COAP_TLS_LIBRARY_NOTLS;
90 return NULL;
91}
92
94}
95
96void
98 dtls_log_level = level;
99}
100
101int
103 return dtls_log_level;
104}
105
106void *
108 return NULL;
109}
110
111void
113}
114
115#if COAP_SERVER_SUPPORT
117 return NULL;
118}
119#endif /* COAP_SERVER_SUPPORT */
120
121#if COAP_CLIENT_SUPPORT
123 return NULL;
124}
125#endif /* COAP_CLIENT_SUPPORT */
126
128}
129
131}
132
133int
135 const uint8_t *data COAP_UNUSED,
136 size_t data_len COAP_UNUSED
137) {
138 return -1;
139}
140
142 return 1;
143}
144
146 return 0;
147}
148
151 return 0;
152}
153
154/*
155 * return 1 timed out
156 * 0 still timing out
157 */
158int
160 return 0;
161}
162
163int
165 const uint8_t *data COAP_UNUSED,
166 size_t data_len COAP_UNUSED
167) {
168 return -1;
169}
170
171#if COAP_SERVER_SUPPORT
172int
174 const uint8_t *data COAP_UNUSED,
175 size_t data_len COAP_UNUSED
176) {
177 return 0;
178}
179#endif /* COAP_SERVER_SUPPORT */
180
182 return 0;
183}
184
185#if COAP_CLIENT_SUPPORT
187 return NULL;
188}
189#endif /* COAP_CLIENT_SUPPORT */
190
191#if COAP_SERVER_SUPPORT
193 return NULL;
194}
195#endif /* COAP_SERVER_SUPPORT */
196
198}
199
201 const uint8_t *data COAP_UNUSED,
202 size_t data_len COAP_UNUSED
203) {
204 return -1;
205}
206
208 uint8_t *data COAP_UNUSED,
209 size_t data_len COAP_UNUSED
210) {
211 return -1;
212}
213
214#if COAP_SERVER_SUPPORT
215typedef struct coap_local_hash_t {
216 size_t ofs;
217 coap_key_t key[8]; /* 32 bytes in total */
218} coap_local_hash_t;
219
221coap_digest_setup(void) {
222 coap_key_t *digest_ctx = coap_malloc(sizeof(coap_local_hash_t));
223
224 if (digest_ctx) {
225 memset(digest_ctx, 0, sizeof(coap_local_hash_t));
226 }
227
228 return digest_ctx;
229}
230
231void
233 coap_free(digest_ctx);
234}
235
236int
238 const uint8_t *data,
239 size_t data_len) {
240 coap_local_hash_t *local = (coap_local_hash_t*)digest_ctx;
241
242 coap_hash(data, data_len, local->key[local->ofs]);
243
244 local->ofs = (local->ofs + 1) % 7;
245 return 1;
246}
247
248int
250 coap_digest_t *digest_buffer) {
251 coap_local_hash_t *local = (coap_local_hash_t*)digest_ctx;
252
253 memcpy(digest_buffer, local->key, sizeof(coap_digest_t));
254
255 coap_digest_free(digest_ctx);
256 return 1;
257}
258#endif /* COAP_SERVER_SUPPORT */
259
260#else /* !HAVE_LIBTINYDTLS && !HAVE_OPENSSL && !HAVE_LIBGNUTLS */
261
262#ifdef __clang__
263/* Make compilers happy that do not like empty modules. As this function is
264 * never used, we ignore -Wunused-function at the end of compiling this file
265 */
266#pragma GCC diagnostic ignored "-Wunused-function"
267#endif
268static inline void dummy(void) {
269}
270
271#endif /* !HAVE_LIBTINYDTLS && !HAVE_OPENSSL && !HAVE_LIBGNUTLS && !HAVE_MBEDTLS */
unsigned char coap_key_t[4]
Definition: coap_hashkey.h:24
#define coap_hash(String, Length, Result)
Definition: coap_hashkey.h:38
Pulls together all the internal only header files.
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:41
coap_tick_t coap_dtls_get_timeout(coap_session_t *session COAP_UNUSED, coap_tick_t now COAP_UNUSED)
Definition: coap_notls.c:150
int 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:134
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:207
coap_tick_t coap_dtls_get_context_timeout(void *dtls_context COAP_UNUSED)
Definition: coap_notls.c:145
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:164
void * coap_dtls_get_tls(const coap_session_t *c_session COAP_UNUSED, coap_tls_library_t *tls_lib)
Definition: coap_notls.c:86
unsigned int coap_dtls_get_overhead(coap_session_t *session COAP_UNUSED)
Definition: coap_notls.c:181
int coap_dtls_context_check_keys_enabled(coap_context_t *ctx COAP_UNUSED)
Definition: coap_notls.c:75
static int dtls_log_level
Definition: coap_notls.c:80
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:200
void coap_dtls_session_update_mtu(coap_session_t *session COAP_UNUSED)
Definition: coap_notls.c:130
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:49
int coap_dtls_handle_timeout(coap_session_t *session COAP_UNUSED)
Definition: coap_notls.c:159
void coap_dtls_free_context(void *handle COAP_UNUSED)
Definition: coap_notls.c:112
void coap_dtls_free_session(coap_session_t *coap_session COAP_UNUSED)
Definition: coap_notls.c:127
void * coap_dtls_new_context(coap_context_t *coap_context COAP_UNUSED)
Definition: coap_notls.c:107
void coap_tls_free_session(coap_session_t *coap_session COAP_UNUSED)
Definition: coap_notls.c:197
COAP_STATIC_INLINE void dummy(void)
Definition: coap_time.c:136
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:127
void coap_dtls_startup(void)
Initialize the underlying (D)TLS Library layer.
Definition: coap_notls.c:82
void * coap_dtls_new_client_session(coap_session_t *coap_session)
Create a new client-side session.
void * coap_tls_new_client_session(coap_session_t *coap_session, int *connected)
Create a new TLS client-side session.
void * coap_tls_new_server_session(coap_session_t *coap_session, int *connected)
Create a TLS new server-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:141
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:93
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:33
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
coap_tls_library_t
Definition: coap_dtls.h:64
@ COAP_TLS_LIBRARY_NOTLS
No DTLS library.
Definition: coap_dtls.h:65
void coap_dtls_set_log_level(int level)
Sets the (D)TLS logging level to the specified level.
Definition: coap_notls.c:97
int coap_dtls_get_log_level(void)
Get the current (D)TLS logging.
Definition: coap_notls.c:102
#define COAP_UNUSED
Definition: libcoap.h:60
COAP_STATIC_INLINE void coap_free(void *object)
Wrapper function to coap_free_type() for backwards compatibility.
Definition: mem.h:110
COAP_STATIC_INLINE void * coap_malloc(size_t size)
Wrapper function to coap_malloc_type() for backwards compatibility.
Definition: mem.h:103
The CoAP stack's global state is stored in a coap_context_t object.
The structure used for defining the Client PSK setup data to be used.
Definition: coap_dtls.h:350
The structure used for defining the PKI setup data to be used.
Definition: coap_dtls.h:256
The structure used for defining the Server PSK setup data to be used.
Definition: coap_dtls.h:437
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:76
coap_tls_library_t type
Library type.
Definition: coap_dtls.h:78
uint64_t version
(D)TLS runtime Library Version
Definition: coap_dtls.h:77