libcoap  4.3.0
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 *
6  * SPDX-License-Identifier: BSD-2-Clause
7  *
8 * This file is part of the CoAP library libcoap. Please see README for terms
9 * of use.
10 */
11 
12 #include "coap3/coap_internal.h"
13 
14 #if !defined(HAVE_LIBTINYDTLS) && !defined(HAVE_OPENSSL) && !defined(HAVE_LIBGNUTLS) && !defined(HAVE_MBEDTLS)
15 
16 int
18  return 0;
19 }
20 
21 int
23  return 0;
24 }
25 
28  static coap_tls_version_t version;
29  version.version = 0;
30  version.type = COAP_TLS_LIBRARY_NOTLS;
31  return &version;
32 }
33 
34 int
36  const coap_dtls_pki_t* setup_data COAP_UNUSED,
37  const coap_dtls_role_t role COAP_UNUSED
38 ) {
39  return 0;
40 }
41 
42 int
44  const char *ca_file COAP_UNUSED,
45  const char *ca_path COAP_UNUSED
46 ) {
47  return 0;
48 }
49 
50 int
52  coap_dtls_cpsk_t* setup_data COAP_UNUSED
53 ) {
54  return 0;
55 }
56 
57 int
59  coap_dtls_spsk_t* setup_data COAP_UNUSED
60 ) {
61  return 0;
62 }
63 
64 int
66 {
67  return 0;
68 }
69 
70 static int dtls_log_level = 0;
71 
72 void coap_dtls_startup(void) {
73 }
74 
75 void *
77  coap_tls_library_t *tls_lib) {
78  if (tls_lib)
79  *tls_lib = COAP_TLS_LIBRARY_NOTLS;
80  return NULL;
81 }
82 
83 void coap_dtls_shutdown(void) {
84 }
85 
86 void
88  dtls_log_level = level;
89 }
90 
91 int
93  return dtls_log_level;
94 }
95 
96 void *
98  return NULL;
99 }
100 
101 void
103 }
104 
106  return NULL;
107 }
108 
110  return NULL;
111 }
112 
114 }
115 
117 }
118 
119 int
121  const uint8_t *data COAP_UNUSED,
122  size_t data_len COAP_UNUSED
123 ) {
124  return -1;
125 }
126 
128  return 1;
129 }
130 
132  return 0;
133 }
134 
137  return 0;
138 }
139 
141 }
142 
143 int
145  const uint8_t *data COAP_UNUSED,
146  size_t data_len COAP_UNUSED
147 ) {
148  return -1;
149 }
150 
151 int
153  const uint8_t *data COAP_UNUSED,
154  size_t data_len COAP_UNUSED
155 ) {
156  return 0;
157 }
158 
160  return 0;
161 }
162 
164  return NULL;
165 }
166 
168  return NULL;
169 }
170 
172 }
173 
175  const uint8_t *data COAP_UNUSED,
176  size_t data_len COAP_UNUSED
177 ) {
178  return -1;
179 }
180 
182  uint8_t *data COAP_UNUSED,
183  size_t data_len COAP_UNUSED
184 ) {
185  return -1;
186 }
187 
188 typedef struct coap_local_hash_t {
189  size_t ofs;
190  coap_key_t key[8]; /* 32 bytes in total */
192 
195  coap_key_t *digest_ctx = coap_malloc(sizeof(coap_local_hash_t));
196 
197  if (digest_ctx) {
198  memset(digest_ctx, 0, sizeof(coap_local_hash_t));
199  }
200 
201  return digest_ctx;
202 }
203 
204 void
206  coap_free(digest_ctx);
207 }
208 
209 int
211  const uint8_t *data,
212  size_t data_len) {
213  coap_local_hash_t *local = (coap_local_hash_t*)digest_ctx;
214 
215  coap_hash(data, data_len, local->key[local->ofs]);
216 
217  local->ofs = (local->ofs + 1) % 7;
218  return 1;
219 }
220 
221 int
223  coap_digest_t *digest_buffer) {
224  coap_local_hash_t *local = (coap_local_hash_t*)digest_ctx;
225 
226  memcpy(digest_buffer, local->key, sizeof(coap_digest_t));
227 
228  coap_digest_free(digest_ctx);
229  return 1;
230 }
231 
232 #else /* !HAVE_LIBTINYDTLS && !HAVE_OPENSSL && !HAVE_LIBGNUTLS */
233 
234 #ifdef __clang__
235 /* Make compilers happy that do not like empty modules. As this function is
236  * never used, we ignore -Wunused-function at the end of compiling this file
237  */
238 #pragma GCC diagnostic ignored "-Wunused-function"
239 #endif
240 static inline void dummy(void) {
241 }
242 
243 #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.
void * coap_dtls_new_server_session(coap_session_t *session COAP_UNUSED)
Definition: coap_notls.c:105
int coap_dtls_context_set_spsk(coap_context_t *ctx COAP_UNUSED, coap_dtls_spsk_t *setup_data COAP_UNUSED)
Definition: coap_notls.c:58
void coap_dtls_handle_timeout(coap_session_t *session COAP_UNUSED)
Definition: coap_notls.c:140
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:35
coap_tick_t coap_dtls_get_timeout(coap_session_t *session COAP_UNUSED, coap_tick_t now COAP_UNUSED)
Definition: coap_notls.c:136
void * coap_dtls_new_context(coap_context_t *coap_context COAP_UNUSED)
Definition: coap_notls.c:97
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:120
void * coap_dtls_new_client_session(coap_session_t *session COAP_UNUSED)
Definition: coap_notls.c:109
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:181
coap_tick_t coap_dtls_get_context_timeout(void *dtls_context COAP_UNUSED)
Definition: coap_notls.c:131
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:144
unsigned int coap_dtls_get_overhead(coap_session_t *session COAP_UNUSED)
Definition: coap_notls.c:159
void * coap_tls_new_client_session(coap_session_t *session COAP_UNUSED, int *connected COAP_UNUSED)
Definition: coap_notls.c:163
void * coap_tls_new_server_session(coap_session_t *session COAP_UNUSED, int *connected COAP_UNUSED)
Definition: coap_notls.c:167
int coap_dtls_hello(coap_session_t *session COAP_UNUSED, const uint8_t *data COAP_UNUSED, size_t data_len COAP_UNUSED)
Definition: coap_notls.c:152
int coap_dtls_context_check_keys_enabled(coap_context_t *ctx COAP_UNUSED)
Definition: coap_notls.c:65
static int dtls_log_level
Definition: coap_notls.c:70
struct coap_local_hash_t coap_local_hash_t
int coap_dtls_context_set_cpsk(coap_context_t *ctx COAP_UNUSED, coap_dtls_cpsk_t *setup_data COAP_UNUSED)
Definition: coap_notls.c:51
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:174
void coap_dtls_session_update_mtu(coap_session_t *session COAP_UNUSED)
Definition: coap_notls.c:116
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:43
void coap_dtls_free_context(void *handle COAP_UNUSED)
Definition: coap_notls.c:102
void coap_dtls_free_session(coap_session_t *coap_session COAP_UNUSED)
Definition: coap_notls.c:113
void * coap_dtls_get_tls(const coap_session_t *c_session COAP_UNUSED, coap_tls_library_t *tls_lib)
Definition: coap_notls.c:76
void coap_tls_free_session(coap_session_t *coap_session COAP_UNUSED)
Definition: coap_notls.c:171
COAP_STATIC_INLINE void dummy(void)
Definition: coap_time.c:131
void coap_digest_free(coap_digest_ctx_t *digest_ctx)
Free off coap_digest_ctx_t.
Definition: coap_notls.c:205
coap_digest_ctx_t * coap_digest_setup(void)
Initialize a coap_digest.
Definition: coap_notls.c:194
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.
Definition: coap_notls.c:222
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.
Definition: coap_notls.c:210
void coap_digest_ctx_t
uint64_t coap_tick_t
This data type represents internal timer ticks with COAP_TICKS_PER_SECOND resolution.
Definition: coap_time.h:122
void coap_dtls_startup(void)
Initialize the underlying (D)TLS Library layer.
Definition: coap_notls.c:72
int coap_dtls_is_context_timeout(void)
Check if timeout is handled per CoAP session or per CoAP context.
Definition: coap_notls.c:127
void coap_dtls_shutdown(void)
Close down the underlying (D)TLS Library layer.
Definition: coap_notls.c:83
coap_dtls_role_t
Definition: coap_dtls.h:31
int coap_tls_is_supported(void)
Check whether TLS is available.
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:27
int coap_dtls_is_supported(void)
Check whether DTLS is available.
Definition: coap_notls.c:17
coap_tls_library_t
Definition: coap_dtls.h:52
@ COAP_TLS_LIBRARY_NOTLS
No DTLS library.
Definition: coap_dtls.h:53
void coap_dtls_set_log_level(int level)
Sets the (D)TLS logging level to the specified level.
Definition: coap_notls.c:87
int coap_dtls_get_log_level(void)
Get the current (D)TLS logging.
Definition: coap_notls.c:92
#define COAP_UNUSED
Definition: libcoap.h:55
COAP_STATIC_INLINE void * coap_malloc(size_t size)
Wrapper function to coap_malloc_type() for backwards compatibility.
Definition: mem.h:98
COAP_STATIC_INLINE void coap_free(void *object)
Wrapper function to coap_free_type() for backwards compatibility.
Definition: mem.h:105
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:338
The structure used for defining the PKI setup data to be used.
Definition: coap_dtls.h:244
The structure used for defining the Server PSK setup data to be used.
Definition: coap_dtls.h:425
coap_key_t key[8]
Definition: coap_notls.c:190
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:64
coap_tls_library_t type
Library type.
Definition: coap_dtls.h:66
uint64_t version
(D)TLS runtime Library Version
Definition: coap_dtls.h:65