coap_server_transport.c
Go to the documentation of this file.
1 /**
2  * @file coap_server_transport.c
3  * @brief Transport protocol abstraction layer
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2026 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.6.4
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL COAP_TRACE_LEVEL
33 
34 //Dependencies
35 #include <stdlib.h>
36 #include "coap/coap_server.h"
39 #include "coap/coap_server_misc.h"
40 #include "debug.h"
41 
42 //Check TCP/IP stack configuration
43 #if (COAP_SERVER_SUPPORT == ENABLED && COAP_SERVER_DTLS_SUPPORT == ENABLED)
44 
45 //Forward declaration of functions
46 error_t coapServerSendCallback(void *handle, const void *data,
47  size_t length, size_t *written, uint_t flags);
48 
49 error_t coapServerReceiveCallback(void *handle, void *data,
50  size_t size, size_t *received, uint_t flags);
51 
53  const DtlsClientParameters *clientParams, uint8_t *cookie,
54  size_t *length, void *param);
55 
57  const DtlsClientParameters *clientParams, const uint8_t *cookie,
58  size_t length, void *param);
59 
60 
61 /**
62  * @brief Accept a new connection from a client
63  * @param[in] context Pointer to the CoAP server context
64  * @param[in] session Pointer to the DTLS session
65  * @return Error code
66  **/
67 
69  CoapDtlsSession *session)
70 {
71  error_t error;
72  TlsState state;
73 
74  //Clear DTLS session
75  osMemset(session, 0, sizeof(CoapDtlsSession));
76 
77  //Initialize session parameters
78  session->context = context;
79  session->interface = context->localInterface;
80  session->serverIpAddr = context->localIpAddr;
81  session->clientIpAddr = context->remoteIpAddr;
82  session->clientPort = context->remotePort;
83  session->timestamp = osGetSystemTime();
84 
85  //Allocate DTLS context
86  session->dtlsContext = tlsInit();
87 
88  //DTLS context successfully created?
89  if(session->dtlsContext != NULL)
90  {
91  //Start of exception handling block
92  do
93  {
94  //Select server operation mode
95  error = tlsSetConnectionEnd(session->dtlsContext,
97  //Any error to report?
98  if(error)
99  break;
100 
101  //Use datagram transport protocol
102  error = tlsSetTransportProtocol(session->dtlsContext,
104  //Any error to report?
105  if(error)
106  break;
107 
108  //Set send and receive callbacks (I/O abstraction layer)
109  error = tlsSetSocketCallbacks(session->dtlsContext,
111  (TlsSocketHandle) session);
112  //Any error to report?
113  if(error)
114  break;
115 
116  //Set cookie generation/verification callbacks
117  error = tlsSetCookieCallbacks(session->dtlsContext,
119  session);
120  //Any error to report?
121  if(error)
122  break;
123 
124 #if (TLS_TICKET_SUPPORT == ENABLED)
125  //Enable session ticket mechanism
126  error = tlsEnableSessionTickets(session->dtlsContext, TRUE);
127  //Any error to report?
128  if(error)
129  return error;
130 
131  //Register ticket encryption/decryption callbacks
132  error = tlsSetTicketCallbacks(session->dtlsContext, tlsEncryptTicket,
133  tlsDecryptTicket, &context->dtlsTicketContext);
134  //Any error to report?
135  if(error)
136  return error;
137 #endif
138 
139  //Invoke user-defined callback, if any
140  if(context->dtlsInitCallback != NULL)
141  {
142  //Perform DTLS related initialization
143  error = context->dtlsInitCallback(context, session->dtlsContext);
144  //Any error to report?
145  if(error)
146  break;
147  }
148 
149  //Initiate DTLS handshake
150  error = tlsConnect(session->dtlsContext);
151  //Any error to report?
152  if(error != NO_ERROR && error != ERROR_WOULD_BLOCK)
153  break;
154 
155  //Retrieve current state
156  state = tlsGetState(session->dtlsContext);
157 
158  //The DTLS server verifies the cookie and proceeds with the handshake
159  //only if it is valid
160  if(state == TLS_STATE_INIT ||
161  state == TLS_STATE_CLIENT_HELLO ||
162  state == TLS_STATE_CLIENT_HELLO_2 ||
163  state == TLS_STATE_CLOSED)
164  {
165  //Do not allocate connection state yet if the stateless cookie
166  //exchange is being performed
167  error = ERROR_WRONG_COOKIE;
168  break;
169  }
170 
171  //The DTLS implementation decides to continue with the connection
172  error = NO_ERROR;
173 
174  //Debug message
175  TRACE_INFO("CoAP Server: DTLS session established with client %s port %"
176  PRIu16 "...\r\n", ipAddrToString(&session->clientIpAddr, NULL),
177  ntohs(session->clientPort));
178 
179  //End of exception handling block
180  } while(0);
181 
182  //Check status code
183  if(error)
184  {
185  //Release DTLS context
186  tlsFree(session->dtlsContext);
187  session->dtlsContext = NULL;
188  }
189  }
190  else
191  {
192  //Failed to allocate DTLS context
193  error = ERROR_OUT_OF_MEMORY;
194  }
195 
196  //Return status code
197  return error;
198 }
199 
200 
201 /**
202  * @brief DTLS session demultiplexing
203  * @param[in] context Pointer to the CoAP server context
204  * @return Error code
205  **/
206 
208 {
209  error_t error;
210  uint_t i;
211  size_t length;
212  systime_t time;
213  CoapDtlsSession *session;
214  CoapDtlsSession *firstFreeSession;
215  CoapDtlsSession *oldestSession;
216 
217  //Initialize status code
218  error = NO_ERROR;
219 
220  //Get current time
221  time = osGetSystemTime();
222 
223  //Keep track of the first free entry
224  firstFreeSession = NULL;
225  //Keep track of the oldest entry
226  oldestSession = NULL;
227 
228  //Demultiplexing of incoming datagrams into separate DTLS sessions
229  for(i = 0; i < context->numSessions; i++)
230  {
231  //Point to the current DTLS session
232  session = &context->sessions[i];
233 
234  //Valid DTLS session?
235  if(session->dtlsContext != NULL)
236  {
237  //Determine if a DTLS session matches the incoming datagram
238  if(session->interface == context->localInterface &&
239  ipCompAddr(&session->serverIpAddr, &context->localIpAddr) &&
240  ipCompAddr(&session->clientIpAddr, &context->remoteIpAddr) &&
241  session->clientPort == context->remotePort)
242  {
243  //Save current time
244  session->timestamp = osGetSystemTime();
245 
246  //The UDP datagram is passed to the DTLS implementation
247  error = tlsRead(session->dtlsContext, context->buffer,
249 
250  //Check status code
251  if(!error)
252  {
253  //Process the received CoAP message
254  error = coapServerProcessMessage(context, context->buffer,
255  length);
256  }
257  else if(error == ERROR_TIMEOUT || error == ERROR_WOULD_BLOCK)
258  {
259  //The UDP datagram contains DTLS handshake messages
260  }
261  else
262  {
263  //Debug message
264  TRACE_INFO("CoAP Server: Failed to read DTLS datagram!\r\n");
265 
266  //Release DTLS session
267  coapServerDeleteSession(session);
268  }
269 
270  //We are done
271  break;
272  }
273  else
274  {
275  //Keep track of the oldest entry
276  if(oldestSession == NULL)
277  {
278  oldestSession = session;
279  }
280  else if((time - session->timestamp) > (time - oldestSession->timestamp))
281  {
282  oldestSession = session;
283  }
284  }
285  }
286  else
287  {
288  //Keep track of the first free entry
289  if(firstFreeSession == NULL)
290  {
291  firstFreeSession = session;
292  }
293  }
294  }
295 
296  //No matching DTLS session?
297  if(i >= context->numSessions)
298  {
299  //Any DTLS session available for use in the table?
300  if(firstFreeSession != NULL)
301  {
302  session = firstFreeSession;
303  }
304  else
305  {
306  //The oldest DTLS session is closed whenever the table runs out of space
307  tlsShutdown(oldestSession->dtlsContext);
308  coapServerDeleteSession(oldestSession);
309 
310  //Point to the DTLS session to be reused
311  session = oldestSession;
312  }
313 
314  //Process the new connection attempt
315  error = coapServerAcceptSession(context, session);
316  }
317 
318  //Return status code
319  return error;
320 }
321 
322 
323 /**
324  * @brief Delete DTLS session
325  * @param[in] session Pointer to the DTLS session
326  **/
327 
329 {
330 #if (COAP_SERVER_OBSERVE_SUPPORT == ENABLED)
331  uint_t i;
332  CoapServerContext *context;
333  CoapObserver *observer;
334 
335  //Point to the CoAP server context
336  context = session->context;
337 
338  //Loop through the list of registered observers
339  for(i = 0; i < context->numObservers; i++)
340  {
341  //Point to the current entry
342  observer = &context->observers[i];
343 
344  //Valid entry?
345  if(observer->state != COAP_OBSERVER_STATE_UNREGISTERED)
346  {
347  //Check whether a matching entry exists in the list
348  if(observer->interface == session->interface &&
349  ipCompAddr(&observer->serverIpAddr, &session->serverIpAddr) &&
350  ipCompAddr(&observer->clientIpAddr, &session->clientIpAddr) &&
351  observer->clientPort == session->clientPort)
352  {
353  //Remove the entry from the list of observers
354  coapServerDeleteObserver(observer);
355  }
356  }
357  }
358 #endif
359 
360  //Debug message
361  TRACE_INFO("CoAP Server: closing DTLS session...\r\n");
362 
363  //Valid DTLS context?
364  if(session->dtlsContext != NULL)
365  {
366  //Release DTLS context
367  tlsFree(session->dtlsContext);
368  session->dtlsContext = NULL;
369  }
370 }
371 
372 
373 /**
374  * @brief DTLS send callback
375  * @param[in] handle Handle referencing a client connection
376  * @param[in] data Pointer to a buffer containing the data to be transmitted
377  * @param[in] length Number of data bytes to send
378  * @param[out] written Number of bytes that have been transmitted
379  * @param[in] flags Unused parameter
380  * @return Error code
381  **/
382 
383 error_t coapServerSendCallback(void *handle, const void *data,
384  size_t length, size_t *written, uint_t flags)
385 {
386  error_t error;
387  SocketMsg msg;
388  CoapServerContext *context;
389  CoapDtlsSession *session;
390 
391  //Point to the DTLS session
392  session = handle;
393  //Point to the CoAP server context
394  context = session->context;
395 
396  //Point to the send buffer
397  msg = SOCKET_DEFAULT_MSG;
398  msg.data = (void *) data;
399  msg.length = length;
400 
401  //Set the source and destination IP addresses
402  msg.interface = session->interface;
403  msg.srcIpAddr = session->serverIpAddr;
404  msg.destIpAddr = session->clientIpAddr;
405  msg.destPort = session->clientPort;
406 
407  //Send datagram
408  error = socketSendMsg(context->socket, &msg, flags);
409 
410  //Check status code
411  if(!error)
412  {
413  //Total number of data bytes successfully transmitted
414  if(written != NULL)
415  {
416  *written = msg.length;
417  }
418  }
419 
420  //Return status code
421  return error;
422 }
423 
424 
425 /**
426  * @brief DTLS receive callback
427  * @param[in] handle Handle referencing a client connection
428  * @param[out] data Buffer where to store the incoming data
429  * @param[in] size Maximum number of bytes that can be received
430  * @param[out] received Number of bytes that have been received
431  * @param[in] flags Unused parameter
432  * @return Error code
433  **/
434 
436  size_t size, size_t *received, uint_t flags)
437 {
438  error_t error;
439  CoapServerContext *context;
440  CoapDtlsSession *session;
441 
442  //Initialize status code
443  error = ERROR_WOULD_BLOCK;
444 
445  //Point to the DTLS session
446  session = (CoapDtlsSession *) handle;
447  //Point to the CoAP server context
448  context = session->context;
449 
450  //Any pending datagram?
451  if(context->bufferLen > 0)
452  {
453  //Pass incoming datagram to the proper connection
454  if(context->localInterface == session->interface &&
455  ipCompAddr(&context->localIpAddr, &session->serverIpAddr) &&
456  ipCompAddr(&context->remoteIpAddr, &session->clientIpAddr) &&
457  context->remotePort == session->clientPort)
458  {
459  //Make sure the length of the datagram is acceptable
460  if(context->bufferLen < size)
461  {
462  //Copy incoming datagram
463  osMemcpy(data, context->buffer, context->bufferLen);
464  //Return the length of the datagram
465  *received = context->bufferLen;
466 
467  //Successful processing
468  error = NO_ERROR;
469  }
470 
471  //Flush the receive buffer
472  context->bufferLen = 0;
473  }
474  }
475 
476  //Return status code
477  return error;
478 }
479 
480 
481 /**
482  * @brief DTLS cookie generation callback function
483  * @param[in] context Pointer to the DTLS context
484  * @param[in] clientParams Client's parameters
485  * @param[out] cookie Pointer to the first byte of the cookie
486  * @param[in,out] length Length of the cookie, in bytes
487  * @param[in] param Pointer to the DTLS session
488  * @return Error code
489  **/
490 
492  const DtlsClientParameters *clientParams, uint8_t *cookie,
493  size_t *length, void *param)
494 {
495  error_t error;
496  CoapDtlsSession *session;
497  HmacContext hmacContext;
498 
499  //Point to the DTLS session
500  session = (CoapDtlsSession *) param;
501 
502  //Debug message
503  TRACE_INFO("CoAP Server: DTLS cookie generation...\r\n");
504 
505  //Make sure the output buffer is large enough to hold the cookie
507  return ERROR_BUFFER_OVERFLOW;
508 
509  //Invalid cookie secret?
510  if(session->context->cookieSecretLen == 0)
511  {
512  //Generate a cookie secret
513  error = context->prngAlgo->generate(context->prngContext,
514  session->context->cookieSecret, COAP_SERVER_MAX_COOKIE_SECRET_SIZE);
515  //Any error to report?
516  if(error)
517  return error;
518 
519  //Save the length of the generated secret
520  session->context->cookieSecretLen = COAP_SERVER_MAX_COOKIE_SECRET_SIZE;
521  }
522 
523  //Initialize HMAC context
524  hmacInit(&hmacContext, SHA256_HASH_ALGO, session->context->cookieSecret,
525  session->context->cookieSecretLen);
526 
527  //Generate stateless cookie
528  hmacUpdate(&hmacContext, (uint8_t *) &session->clientIpAddr + sizeof(size_t),
529  session->clientIpAddr.length);
530 
531  //The server should use client parameters (version, random, session_id,
532  //cipher_suites, compression_method) to generate its cookie
533  hmacUpdate(&hmacContext, &clientParams->version, sizeof(uint16_t));
534  hmacUpdate(&hmacContext, clientParams->random, clientParams->randomLen);
535  hmacUpdate(&hmacContext, clientParams->sessionId, clientParams->sessionIdLen);
536  hmacUpdate(&hmacContext, clientParams->cipherSuites, clientParams->cipherSuitesLen);
537  hmacUpdate(&hmacContext, clientParams->compressMethods, clientParams->compressMethodsLen);
538 
539  //The cookie allows the server to offload state to the client
540  hmacUpdate(&hmacContext, clientParams->state, clientParams->stateLen);
541 
542  //Finalize HMAC computation
543  hmacFinal(&hmacContext, cookie);
544 
545  //Return the length of the cookie
547 
548  //Successful processing
549  return NO_ERROR;
550 }
551 
552 
553 /**
554  * @brief DTLS cookie verification callback function
555  * @param[in] context Pointer to the DTLS context
556  * @param[in] clientParams Client's parameters
557  * @param[in] cookie Pointer to the first byte of the cookie
558  * @param[in] length Length of the cookie, in bytes
559  * @param[in] param Pointer to the DTLS session
560  * @return Error code
561  **/
562 
564  const DtlsClientParameters *clientParams, const uint8_t *cookie,
565  size_t length, void *param)
566 {
567  error_t error;
568  CoapDtlsSession *session;
569  HmacContext hmacContext;
570 
571  //Point to the DTLS session
572  session = (CoapDtlsSession *) param;
573 
574  //Debug message
575  TRACE_INFO("CoAP Server: DTLS cookie verification...\r\n");
576 
577  //Make sure the length of the cookie is acceptable
579  return ERROR_WRONG_COOKIE;
580 
581  //Invalid cookie secret?
582  if(session->context->cookieSecretLen == 0)
583  {
584  //Generate a cookie secret
585  error = context->prngAlgo->generate(context->prngContext,
586  session->context->cookieSecret, COAP_SERVER_MAX_COOKIE_SECRET_SIZE);
587  //Any error to report?
588  if(error)
589  return error;
590 
591  //Save the length of the generated secret
592  session->context->cookieSecretLen = COAP_SERVER_MAX_COOKIE_SECRET_SIZE;
593  }
594 
595  //Initialize HMAC context
596  hmacInit(&hmacContext, SHA256_HASH_ALGO, session->context->cookieSecret,
597  session->context->cookieSecretLen);
598 
599  //Generate stateless cookie
600  hmacUpdate(&hmacContext, (uint8_t *) &session->clientIpAddr + sizeof(size_t),
601  session->clientIpAddr.length);
602 
603  //The server should use client parameters (version, random, session_id,
604  //cipher_suites, compression_method) to generate its cookie
605  hmacUpdate(&hmacContext, &clientParams->version, sizeof(uint16_t));
606  hmacUpdate(&hmacContext, clientParams->random, clientParams->randomLen);
607  hmacUpdate(&hmacContext, clientParams->sessionId, clientParams->sessionIdLen);
608  hmacUpdate(&hmacContext, clientParams->cipherSuites, clientParams->cipherSuitesLen);
609  hmacUpdate(&hmacContext, clientParams->compressMethods, clientParams->compressMethodsLen);
610 
611  //The cookie allows the server to offload state to the client
612  hmacUpdate(&hmacContext, clientParams->state, clientParams->stateLen);
613 
614  //Finalize HMAC computation
615  hmacFinal(&hmacContext, NULL);
616 
617  //Compare the received cookie against the expected value
618  if(osMemcmp(cookie, hmacContext.digest, length) == 0)
619  {
620  //The cookie is valid
621  error = NO_ERROR;
622  }
623  else
624  {
625  //The cookie is invalid
626  error = ERROR_WRONG_COOKIE;
627  }
628 
629  //Return status code
630  return error;
631 }
632 
633 #endif
TlsContext * tlsInit(void)
TLS context initialization.
Definition: tls.c:68
const uint8_t * random
Definition: dtls_misc.h:230
error_t tlsSetConnectionEnd(TlsContext *context, TlsConnectionEnd entity)
Set operation mode (client or server)
Definition: tls.c:371
#define SHA256_HASH_ALGO
Definition: sha256.h:49
HMAC algorithm context.
Definition: hmac.h:59
error_t tlsSetTransportProtocol(TlsContext *context, TlsTransportProtocol transportProtocol)
Set the transport protocol to be used.
Definition: tls.c:340
@ ERROR_WOULD_BLOCK
Definition: error.h:96
error_t tlsDecryptTicket(TlsContext *context, const uint8_t *ciphertext, size_t ciphertextLen, uint8_t *plaintext, size_t *plaintextLen, void *param)
Session ticket decryption.
Definition: tls_ticket.c:221
@ ERROR_BUFFER_OVERFLOW
Definition: error.h:143
TlsState
TLS FSM states.
Definition: tls.h:1582
#define TRUE
Definition: os_port.h:50
uint8_t data[]
Definition: ethernet.h:224
Message and ancillary data.
Definition: socket.h:241
@ TLS_TRANSPORT_PROTOCOL_DATAGRAM
Definition: tls.h:1038
char_t * ipAddrToString(const IpAddr *ipAddr, char_t *str)
Convert a binary IP address to a string representation.
Definition: ip.c:810
error_t coapServerCookieGenerateCallback(TlsContext *context, const DtlsClientParameters *clientParams, uint8_t *cookie, size_t *length, void *param)
DTLS cookie generation callback function.
#define CoapObserver
Definition: coap_server.h:176
void * data
Pointer to the payload.
Definition: socket.h:242
#define osMemcmp(p1, p2, length)
Definition: os_port.h:159
@ ERROR_OUT_OF_MEMORY
Definition: error.h:63
Helper functions for CoAP server.
@ ERROR_WRONG_COOKIE
Definition: error.h:92
error_t coapServerProcessMessage(CoapServerContext *context, const uint8_t *data, size_t length)
Process CoAP message.
@ TLS_STATE_CLIENT_HELLO
Definition: tls.h:1584
error_t coapServerCookieVerifyCallback(TlsContext *context, const DtlsClientParameters *clientParams, const uint8_t *cookie, size_t length, void *param)
DTLS cookie verification callback function.
error_t coapServerSendCallback(void *handle, const void *data, size_t length, size_t *written, uint_t flags)
DTLS send callback.
uint16_t destPort
Destination port.
Definition: socket.h:252
@ COAP_OBSERVER_STATE_UNREGISTERED
Definition: coap_server.h:190
error_t socketSendMsg(Socket *socket, const SocketMsg *message, uint_t flags)
Send a message to a connectionless socket.
Definition: socket.c:1666
NetInterface * interface
Underlying network interface.
Definition: socket.h:248
error_t tlsShutdown(TlsContext *context)
Gracefully close TLS session.
Definition: tls.c:2621
const SocketMsg SOCKET_DEFAULT_MSG
Definition: socket.c:52
size_t length
Actual length of the payload, in bytes.
Definition: socket.h:244
void coapServerDeleteObserver(CoapObserver *observer)
Remove an entry from the list of observers.
#define osMemcpy(dest, src, length)
Definition: os_port.h:147
#define TlsContext
Definition: tls.h:36
error_t
Error codes.
Definition: error.h:43
bool_t ipCompAddr(const IpAddr *ipAddr1, const IpAddr *ipAddr2)
Compare IP addresses.
Definition: ip.c:318
@ TLS_CONNECTION_END_SERVER
Definition: tls.h:1051
error_t tlsSetTicketCallbacks(TlsContext *context, TlsTicketEncryptCallback ticketEncryptCallback, TlsTicketDecryptCallback ticketDecryptCallback, void *param)
Set ticket encryption/decryption callbacks.
Definition: tls.c:1557
Client parameters.
Definition: dtls_misc.h:228
const uint8_t * cipherSuites
Definition: dtls_misc.h:234
void coapServerDeleteSession(CoapDtlsSession *session)
Delete DTLS session.
IpAddr srcIpAddr
Source IP address.
Definition: socket.h:249
error_t tlsEnableSessionTickets(TlsContext *context, bool_t enabled)
Enable session ticket mechanism.
Definition: tls.c:1424
#define TRACE_INFO(...)
Definition: debug.h:105
uint8_t length
Definition: tcp.h:375
error_t tlsRead(TlsContext *context, void *data, size_t size, size_t *received, uint_t flags)
Receive application data from a the remote host using TLS.
Definition: tls.c:2286
#define CoapDtlsSession
Definition: coap_server.h:168
uint32_t systime_t
System time.
CoAP server.
#define ntohs(value)
Definition: cpu_endian.h:421
__weak_func void hmacUpdate(HmacContext *context, const void *data, size_t length)
Update the HMAC context with a portion of the message being hashed.
Definition: hmac.c:201
IpAddr destIpAddr
Destination IP address.
Definition: socket.h:251
@ ERROR_TIMEOUT
Definition: error.h:95
uint8_t digest[MAX_HASH_DIGEST_SIZE]
Definition: hmac.h:63
@ TLS_STATE_CLIENT_HELLO_2
Definition: tls.h:1585
uint32_t time
error_t coapServerDemultiplexSession(CoapServerContext *context)
DTLS session demultiplexing.
TlsState tlsGetState(TlsContext *context)
Retrieve current TLS state.
Definition: tls.c:220
__weak_func void hmacFinal(HmacContext *context, uint8_t *digest)
Finish the HMAC calculation.
Definition: hmac.c:218
#define CoapServerContext
Definition: coap_server.h:164
@ TLS_STATE_INIT
Definition: tls.h:1583
error_t tlsEncryptTicket(TlsContext *context, const uint8_t *plaintext, size_t plaintextLen, uint8_t *ciphertext, size_t *ciphertextLen, void *param)
Session ticket encryption.
Definition: tls_ticket.c:81
Transport protocol abstraction layer.
error_t tlsSetSocketCallbacks(TlsContext *context, TlsSocketSendCallback socketSendCallback, TlsSocketReceiveCallback socketReceiveCallback, TlsSocketHandle handle)
Set socket send and receive callbacks.
Definition: tls.c:270
const uint8_t * sessionId
Definition: dtls_misc.h:232
error_t coapServerAcceptSession(CoapServerContext *context, CoapDtlsSession *session)
Accept a new connection from a client.
const uint8_t * compressMethods
Definition: dtls_misc.h:236
uint8_t cookie[]
Definition: dtls_misc.h:211
void tlsFree(TlsContext *context)
Release TLS context.
Definition: tls.c:2816
error_t coapServerReceiveCallback(void *handle, void *data, size_t size, size_t *received, uint_t flags)
DTLS receive callback.
size_t compressMethodsLen
Definition: dtls_misc.h:237
uint8_t flags
Definition: tcp.h:358
#define COAP_SERVER_MAX_COOKIE_SECRET_SIZE
Definition: coap_server.h:133
error_t tlsSetCookieCallbacks(TlsContext *context, DtlsCookieGenerateCallback cookieGenerateCallback, DtlsCookieVerifyCallback cookieVerifyCallback, void *param)
Set cookie generation/verification callbacks (for DTLS only)
Definition: tls.c:1647
unsigned int uint_t
Definition: compiler_port.h:57
#define osMemset(p, value, length)
Definition: os_port.h:141
__weak_func error_t hmacInit(HmacContext *context, const HashAlgo *hash, const void *key, size_t keyLen)
Initialize HMAC calculation.
Definition: hmac.c:140
#define SHA256_DIGEST_SIZE
Definition: sha256.h:45
#define COAP_SERVER_BUFFER_SIZE
Definition: coap_server.h:119
error_t tlsConnect(TlsContext *context)
Initiate the TLS handshake.
Definition: tls.c:1805
@ NO_ERROR
Success.
Definition: error.h:44
Debugging facilities.
void * TlsSocketHandle
Socket handle.
Definition: tls.h:2073
const uint8_t * state
Definition: dtls_misc.h:238
systime_t osGetSystemTime(void)
Retrieve system time.
@ TLS_STATE_CLOSED
Definition: tls.h:1620