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 #include "coap3/coap_dtls.h"
14
15 #if !defined(HAVE_LIBTINYDTLS) && !defined(HAVE_OPENSSL) && !defined(HAVE_LIBGNUTLS) && !defined(HAVE_MBEDTLS)
16
17 int
coap_dtls_is_supported(void)18 coap_dtls_is_supported(void) {
19 return 0;
20 }
21
22 int
coap_tls_is_supported(void)23 coap_tls_is_supported(void) {
24 return 0;
25 }
26
27 coap_tls_version_t *
coap_get_tls_library_version(void)28 coap_get_tls_library_version(void) {
29 static coap_tls_version_t version;
30 version.version = 0;
31 version.type = COAP_TLS_LIBRARY_NOTLS;
32 return &version;
33 }
34
35 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)36 coap_dtls_context_set_pki(coap_context_t *ctx COAP_UNUSED,
37 const coap_dtls_pki_t* setup_data COAP_UNUSED,
38 const coap_dtls_role_t role COAP_UNUSED
39 ) {
40 return 0;
41 }
42
43 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)44 coap_dtls_context_set_pki_root_cas(coap_context_t *ctx COAP_UNUSED,
45 const char *ca_file COAP_UNUSED,
46 const char *ca_path COAP_UNUSED
47 ) {
48 return 0;
49 }
50
51 int
coap_dtls_context_set_cpsk(coap_context_t * ctx COAP_UNUSED,coap_dtls_cpsk_t * setup_data COAP_UNUSED)52 coap_dtls_context_set_cpsk(coap_context_t *ctx COAP_UNUSED,
53 coap_dtls_cpsk_t* setup_data COAP_UNUSED
54 ) {
55 return 0;
56 }
57
58 int
coap_dtls_context_set_spsk(coap_context_t * ctx COAP_UNUSED,coap_dtls_spsk_t * setup_data COAP_UNUSED)59 coap_dtls_context_set_spsk(coap_context_t *ctx COAP_UNUSED,
60 coap_dtls_spsk_t* setup_data COAP_UNUSED
61 ) {
62 return 0;
63 }
64
65 int
coap_dtls_context_check_keys_enabled(coap_context_t * ctx COAP_UNUSED)66 coap_dtls_context_check_keys_enabled(coap_context_t *ctx COAP_UNUSED)
67 {
68 return 0;
69 }
70
71 static int dtls_log_level = 0;
72
coap_dtls_startup(void)73 void coap_dtls_startup(void) {
74 }
75
76 void *
coap_dtls_get_tls(const coap_session_t * c_session COAP_UNUSED,coap_tls_library_t * tls_lib)77 coap_dtls_get_tls(const coap_session_t *c_session COAP_UNUSED,
78 coap_tls_library_t *tls_lib) {
79 if (tls_lib)
80 *tls_lib = COAP_TLS_LIBRARY_NOTLS;
81 return NULL;
82 }
83
coap_dtls_shutdown(void)84 void coap_dtls_shutdown(void) {
85 }
86
87 void
coap_dtls_set_log_level(int level)88 coap_dtls_set_log_level(int level) {
89 dtls_log_level = level;
90 }
91
92 int
coap_dtls_get_log_level(void)93 coap_dtls_get_log_level(void) {
94 return dtls_log_level;
95 }
96
97 void *
coap_dtls_new_context(coap_context_t * coap_context COAP_UNUSED)98 coap_dtls_new_context(coap_context_t *coap_context COAP_UNUSED) {
99 return NULL;
100 }
101
102 void
coap_dtls_free_context(void * handle COAP_UNUSED)103 coap_dtls_free_context(void *handle COAP_UNUSED) {
104 }
105
coap_dtls_new_server_session(coap_session_t * session COAP_UNUSED)106 void *coap_dtls_new_server_session(coap_session_t *session COAP_UNUSED) {
107 return NULL;
108 }
109
coap_dtls_new_client_session(coap_session_t * session COAP_UNUSED)110 void *coap_dtls_new_client_session(coap_session_t *session COAP_UNUSED) {
111 return NULL;
112 }
113
coap_dtls_free_session(coap_session_t * coap_session COAP_UNUSED)114 void coap_dtls_free_session(coap_session_t *coap_session COAP_UNUSED) {
115 }
116
coap_dtls_session_update_mtu(coap_session_t * session COAP_UNUSED)117 void coap_dtls_session_update_mtu(coap_session_t *session COAP_UNUSED) {
118 }
119
120 int
coap_dtls_send(coap_session_t * session COAP_UNUSED,const uint8_t * data COAP_UNUSED,size_t data_len COAP_UNUSED)121 coap_dtls_send(coap_session_t *session COAP_UNUSED,
122 const uint8_t *data COAP_UNUSED,
123 size_t data_len COAP_UNUSED
124 ) {
125 return -1;
126 }
127
coap_dtls_is_context_timeout(void)128 int coap_dtls_is_context_timeout(void) {
129 return 1;
130 }
131
coap_dtls_get_context_timeout(void * dtls_context COAP_UNUSED)132 coap_tick_t coap_dtls_get_context_timeout(void *dtls_context COAP_UNUSED) {
133 return 0;
134 }
135
136 coap_tick_t
coap_dtls_get_timeout(coap_session_t * session COAP_UNUSED,coap_tick_t now COAP_UNUSED)137 coap_dtls_get_timeout(coap_session_t *session COAP_UNUSED, coap_tick_t now COAP_UNUSED) {
138 return 0;
139 }
140
coap_dtls_handle_timeout(coap_session_t * session COAP_UNUSED)141 void coap_dtls_handle_timeout(coap_session_t *session COAP_UNUSED) {
142 }
143
144 int
coap_dtls_receive(coap_session_t * session COAP_UNUSED,const uint8_t * data COAP_UNUSED,size_t data_len COAP_UNUSED)145 coap_dtls_receive(coap_session_t *session COAP_UNUSED,
146 const uint8_t *data COAP_UNUSED,
147 size_t data_len COAP_UNUSED
148 ) {
149 return -1;
150 }
151
152 int
coap_dtls_hello(coap_session_t * session COAP_UNUSED,const uint8_t * data COAP_UNUSED,size_t data_len COAP_UNUSED)153 coap_dtls_hello(coap_session_t *session COAP_UNUSED,
154 const uint8_t *data COAP_UNUSED,
155 size_t data_len COAP_UNUSED
156 ) {
157 return 0;
158 }
159
coap_dtls_get_overhead(coap_session_t * session COAP_UNUSED)160 unsigned int coap_dtls_get_overhead(coap_session_t *session COAP_UNUSED) {
161 return 0;
162 }
163
coap_tls_new_client_session(coap_session_t * session COAP_UNUSED,int * connected COAP_UNUSED)164 void *coap_tls_new_client_session(coap_session_t *session COAP_UNUSED, int *connected COAP_UNUSED) {
165 return NULL;
166 }
167
coap_tls_new_server_session(coap_session_t * session COAP_UNUSED,int * connected COAP_UNUSED)168 void *coap_tls_new_server_session(coap_session_t *session COAP_UNUSED, int *connected COAP_UNUSED) {
169 return NULL;
170 }
171
coap_tls_free_session(coap_session_t * coap_session COAP_UNUSED)172 void coap_tls_free_session(coap_session_t *coap_session COAP_UNUSED) {
173 }
174
coap_tls_write(coap_session_t * session COAP_UNUSED,const uint8_t * data COAP_UNUSED,size_t data_len COAP_UNUSED)175 ssize_t coap_tls_write(coap_session_t *session COAP_UNUSED,
176 const uint8_t *data COAP_UNUSED,
177 size_t data_len COAP_UNUSED
178 ) {
179 return -1;
180 }
181
coap_tls_read(coap_session_t * session COAP_UNUSED,uint8_t * data COAP_UNUSED,size_t data_len COAP_UNUSED)182 ssize_t coap_tls_read(coap_session_t *session COAP_UNUSED,
183 uint8_t *data COAP_UNUSED,
184 size_t data_len COAP_UNUSED
185 ) {
186 return -1;
187 }
188
189 typedef struct coap_local_hash_t {
190 size_t ofs;
191 coap_key_t key[8]; /* 32 bytes in total */
192 } coap_local_hash_t;
193
194 coap_digest_ctx_t *
coap_digest_setup(void)195 coap_digest_setup(void) {
196 coap_key_t *digest_ctx = coap_malloc(sizeof(coap_local_hash_t));
197
198 if (digest_ctx) {
199 memset(digest_ctx, 0, sizeof(coap_local_hash_t));
200 }
201
202 return digest_ctx;
203 }
204
205 void
coap_digest_free(coap_digest_ctx_t * digest_ctx)206 coap_digest_free(coap_digest_ctx_t *digest_ctx) {
207 coap_free(digest_ctx);
208 }
209
210 int
coap_digest_update(coap_digest_ctx_t * digest_ctx,const uint8_t * data,size_t data_len)211 coap_digest_update(coap_digest_ctx_t *digest_ctx,
212 const uint8_t *data,
213 size_t data_len) {
214 coap_local_hash_t *local = (coap_local_hash_t*)digest_ctx;
215
216 coap_hash(data, data_len, local->key[local->ofs]);
217
218 local->ofs = (local->ofs + 1) % 7;
219 return 1;
220 }
221
222 int
coap_digest_final(coap_digest_ctx_t * digest_ctx,coap_digest_t * digest_buffer)223 coap_digest_final(coap_digest_ctx_t *digest_ctx,
224 coap_digest_t *digest_buffer) {
225 coap_local_hash_t *local = (coap_local_hash_t*)digest_ctx;
226
227 memcpy(digest_buffer, local->key, sizeof(coap_digest_t));
228
229 coap_digest_free(digest_ctx);
230 return 1;
231 }
232
233 #else /* !HAVE_LIBTINYDTLS && !HAVE_OPENSSL && !HAVE_LIBGNUTLS */
234
235 #ifdef __clang__
236 /* Make compilers happy that do not like empty modules. As this function is
237 * never used, we ignore -Wunused-function at the end of compiling this file
238 */
239 #pragma GCC diagnostic ignored "-Wunused-function"
240 #endif
dummy(void)241 static inline void dummy(void) {
242 }
243
244 #endif /* !HAVE_LIBTINYDTLS && !HAVE_OPENSSL && !HAVE_LIBGNUTLS && !HAVE_MBEDTLS */
245