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