libcoap  4.3.0rc1
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 "coap2/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 coap_dtls_shutdown(void) {
74 }
75 
76 void
78  dtls_log_level = level;
79 }
80 
81 int
83  return dtls_log_level;
84 }
85 
86 void *
88  return NULL;
89 }
90 
91 void
93 }
94 
96  return NULL;
97 }
98 
100  return NULL;
101 }
102 
104 }
105 
107 }
108 
109 int
111  const uint8_t *data COAP_UNUSED,
112  size_t data_len COAP_UNUSED
113 ) {
114  return -1;
115 }
116 
118  return 1;
119 }
120 
122  return 0;
123 }
124 
127  return 0;
128 }
129 
131 }
132 
133 int
135  const uint8_t *data COAP_UNUSED,
136  size_t data_len COAP_UNUSED
137 ) {
138  return -1;
139 }
140 
141 int
143  const uint8_t *data COAP_UNUSED,
144  size_t data_len COAP_UNUSED
145 ) {
146  return 0;
147 }
148 
150  return 0;
151 }
152 
154  return NULL;
155 }
156 
158  return NULL;
159 }
160 
162 }
163 
165  const uint8_t *data COAP_UNUSED,
166  size_t data_len COAP_UNUSED
167 ) {
168  return -1;
169 }
170 
172  uint8_t *data COAP_UNUSED,
173  size_t data_len COAP_UNUSED
174 ) {
175  return -1;
176 }
177 
178 typedef struct coap_local_hash_t {
179  size_t ofs;
180  coap_key_t key[8]; /* 32 bytes in total */
182 
185  coap_key_t *digest_ctx = coap_malloc(sizeof(coap_local_hash_t));
186 
187  if (digest_ctx) {
188  memset(digest_ctx, 0, sizeof(coap_local_hash_t));
189  }
190 
191  return digest_ctx;
192 }
193 
194 void
196  coap_free(digest_ctx);
197 }
198 
199 int
201  const uint8_t *data,
202  size_t data_len) {
203  coap_local_hash_t *local = (coap_local_hash_t*)digest_ctx;
204 
205  coap_hash(data, data_len, local->key[local->ofs]);
206 
207  local->ofs = (local->ofs + 1) % 7;
208  return 1;
209 }
210 
211 int
213  coap_digest_t *digest_buffer) {
214  coap_local_hash_t *local = (coap_local_hash_t*)digest_ctx;
215 
216  memcpy(digest_buffer, local->key, sizeof(coap_digest_t));
217 
218  coap_digest_free(digest_ctx);
219  return 1;
220 }
221 
222 #else /* !HAVE_LIBTINYDTLS && !HAVE_OPENSSL && !HAVE_LIBGNUTLS */
223 
224 #ifdef __clang__
225 /* Make compilers happy that do not like empty modules. As this function is
226  * never used, we ignore -Wunused-function at the end of compiling this file
227  */
228 #pragma GCC diagnostic ignored "-Wunused-function"
229 #endif
230 static inline void dummy(void) {
231 }
232 
233 #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:95
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:130
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:126
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:110
void * coap_dtls_new_client_session(coap_session_t *session COAP_UNUSED)
Definition: coap_notls.c:99
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:171
coap_tick_t coap_dtls_get_context_timeout(void *dtls_context COAP_UNUSED)
Definition: coap_notls.c:121
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:134
unsigned int coap_dtls_get_overhead(coap_session_t *session COAP_UNUSED)
Definition: coap_notls.c:149
void * coap_tls_new_client_session(coap_session_t *session COAP_UNUSED, int *connected COAP_UNUSED)
Definition: coap_notls.c:153
void * coap_tls_new_server_session(coap_session_t *session COAP_UNUSED, int *connected COAP_UNUSED)
Definition: coap_notls.c:157
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:142
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:164
int coap_dtls_context_set_pki_root_cas(struct 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_session_update_mtu(coap_session_t *session COAP_UNUSED)
Definition: coap_notls.c:106
void coap_dtls_free_context(void *handle COAP_UNUSED)
Definition: coap_notls.c:92
void coap_dtls_free_session(coap_session_t *coap_session COAP_UNUSED)
Definition: coap_notls.c:103
void * coap_dtls_new_context(struct coap_context_t *coap_context COAP_UNUSED)
Definition: coap_notls.c:87
void coap_tls_free_session(coap_session_t *coap_session COAP_UNUSED)
Definition: coap_notls.c:161
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:195
coap_digest_ctx_t * coap_digest_setup(void)
Initialize a coap_digest.
Definition: coap_notls.c:184
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:212
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:200
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
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:117
void coap_dtls_shutdown(void)
Close down the underlying (D)TLS Library layer.
Definition: coap_notls.c:73
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_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:77
int coap_dtls_get_log_level(void)
Get the current (D)TLS logging.
Definition: coap_notls.c:82
#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.
Definition: net.h:150
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:180
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