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