Loading...
Searching...
No Matches
dtls.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2019 HAW Hamburg
3 * Freie Universität Berlin
4 * Inria
5 * Daniele Lacamera
6 * Ken Bannister
7 *
8 * This file is subject to the terms and conditions of the GNU Lesser
9 * General Public License v2.1. See the file LICENSE in the top level
10 * directory for more details.
11 */
12
13#pragma once
14
534
535#include <assert.h>
536#include <errno.h>
537#include <stdint.h>
538#include <stdlib.h>
539#include <sys/types.h>
540
541/* net/sock/async/types.h included by net/sock.h needs to re-typedef the
542 * `sock_dtls_t` to prevent cyclic includes */
543#if defined (__clang__)
544# pragma clang diagnostic push
545# pragma clang diagnostic ignored "-Wtypedef-redefinition"
546#endif
547
548#include "net/sock.h"
549#include "net/sock/udp.h"
550#include "net/credman.h"
551
552#ifdef __cplusplus
553extern "C" {
554#endif
555
569#ifndef CONFIG_DTLS_HANDSHAKE_BUFSIZE_EXP
570#define CONFIG_DTLS_HANDSHAKE_BUFSIZE_EXP 8
571#endif
573
577#ifndef DTLS_HANDSHAKE_BUFSIZE
578#define DTLS_HANDSHAKE_BUFSIZE (1 << CONFIG_DTLS_HANDSHAKE_BUFSIZE_EXP)
579#endif
580
584#define SOCK_DTLS_HANDSHAKE (EXDEV)
585
589#ifndef CONFIG_DTLS_FORCE_EXTENDED_MASTER_SECRET
590#define CONFIG_DTLS_FORCE_EXTENDED_MASTER_SECRET 1
591#endif
592
596#ifndef CONFIG_DTLS_FORCE_RENEGOTIATION_INFO
597#define CONFIG_DTLS_FORCE_RENEGOTIATION_INFO 1
598#endif
599
605enum {
609};
611
617enum {
620};
622
629typedef struct sock_dtls sock_dtls_t;
630
631#if defined (__clang__)
632# pragma clang diagnostic pop
633#endif
634
639
649
659
665void sock_dtls_init(void);
666
690 credman_tag_t tag, unsigned version, unsigned role);
691
702
721 sock_dtls_session_t *remote);
722
737
747 sock_udp_ep_t *ep);
748
761 const sock_udp_ep_t *ep);
762
793 void *data, size_t maxlen, uint32_t timeout,
794 sock_dtls_aux_rx_t *aux);
795
823static inline ssize_t sock_dtls_recv(sock_dtls_t *sock,
824 sock_dtls_session_t *remote,
825 void *data, size_t maxlen,
826 uint32_t timeout)
827{
828 return sock_dtls_recv_aux(sock, remote, data, maxlen, timeout, NULL);
829}
830
874 void **data, void **buf_ctx, uint32_t timeout,
875 sock_dtls_aux_rx_t *aux);
876
917static inline ssize_t sock_dtls_recv_buf(sock_dtls_t *sock,
918 sock_dtls_session_t *remote,
919 void **data, void **buf_ctx,
920 uint32_t timeout)
921{
922 return sock_dtls_recv_buf_aux(sock, remote, data, buf_ctx, timeout, NULL);
923}
924
960 const iolist_t *snips, uint32_t timeout,
961 sock_dtls_aux_tx_t *aux);
962
997static inline ssize_t sock_dtls_send_aux(sock_dtls_t *sock,
998 sock_dtls_session_t *remote,
999 const void *data, size_t len,
1000 uint32_t timeout,
1001 sock_dtls_aux_tx_t *aux)
1002{
1003 const iolist_t snip = {
1004 .iol_base = (void *)data,
1005 .iol_len = len,
1006 };
1007
1008 return sock_dtls_sendv_aux(sock, remote, &snip, timeout, aux);
1009}
1010
1051static inline ssize_t sock_dtls_send(sock_dtls_t *sock,
1052 sock_dtls_session_t *remote,
1053 const void *data, size_t len,
1054 uint32_t timeout)
1055{
1056 return sock_dtls_send_aux(sock, remote, data, len, timeout, NULL);
1057}
1058
1099static inline ssize_t sock_dtls_sendv(sock_dtls_t *sock,
1100 sock_dtls_session_t *remote,
1101 const iolist_t *snips,
1102 uint32_t timeout)
1103{
1104 return sock_dtls_sendv_aux(sock, remote, snips, timeout, NULL);
1105}
1106
1120
1121#ifdef MODULE_SOCK_DTLS
1122#include "sock_dtls_types.h"
1123#endif
1124
1125#ifdef __cplusplus
1126}
1127#endif
1128
POSIX.1-2008 compliant version of the assert macro.
(D)TLS credentials management module definitions
uint16_t credman_tag_t
Tag of the credential.
Definition credman.h:95
struct sock_udp sock_udp_t
forward declare for async
Definition types.h:139
struct sock_dtls sock_dtls_t
forward declare for async
Definition types.h:47
static ssize_t sock_dtls_recv_buf(sock_dtls_t *sock, sock_dtls_session_t *remote, void **data, void **buf_ctx, uint32_t timeout)
Decrypts and provides stack-internal buffer space containing a message from a remote peer.
Definition dtls.h:917
int sock_dtls_create(sock_dtls_t *sock, sock_udp_t *udp_sock, credman_tag_t tag, unsigned version, unsigned role)
Creates a new DTLS sock object.
static ssize_t sock_dtls_sendv(sock_dtls_t *sock, sock_dtls_session_t *remote, const iolist_t *snips, uint32_t timeout)
Encrypts and sends a message to a remote peer with non-continuous payload.
Definition dtls.h:1099
static ssize_t sock_dtls_send_aux(sock_dtls_t *sock, sock_dtls_session_t *remote, const void *data, size_t len, uint32_t timeout, sock_dtls_aux_tx_t *aux)
Encrypts and sends a message to a remote peer.
Definition dtls.h:997
ssize_t sock_dtls_recv_buf_aux(sock_dtls_t *sock, sock_dtls_session_t *remote, void **data, void **buf_ctx, uint32_t timeout, sock_dtls_aux_rx_t *aux)
Decrypts and provides stack-internal buffer space containing a message from a remote peer.
void sock_dtls_close(sock_dtls_t *sock)
Closes a DTLS sock.
void sock_dtls_init(void)
Called exactly once during auto_init.
void sock_dtls_session_destroy(sock_dtls_t *sock, sock_dtls_session_t *remote)
Destroys an existing DTLS session.
static ssize_t sock_dtls_send(sock_dtls_t *sock, sock_dtls_session_t *remote, const void *data, size_t len, uint32_t timeout)
Encrypts and sends a message to a remote peer.
Definition dtls.h:1051
int sock_dtls_session_init(sock_dtls_t *sock, const sock_udp_ep_t *ep, sock_dtls_session_t *remote)
Initialize session handshake.
sock_udp_t * sock_dtls_get_udp_sock(sock_dtls_t *sock)
Get underlying UDP sock.
struct sock_dtls_session sock_dtls_session_t
Information about a created session.
Definition dtls.h:638
static ssize_t sock_dtls_recv(sock_dtls_t *sock, sock_dtls_session_t *remote, void *data, size_t maxlen, uint32_t timeout)
Receive handshake messages and application data from remote peer.
Definition dtls.h:823
ssize_t sock_dtls_recv_aux(sock_dtls_t *sock, sock_dtls_session_t *remote, void *data, size_t maxlen, uint32_t timeout, sock_dtls_aux_rx_t *aux)
Receive handshake messages and application data from remote peer.
sock_udp_aux_rx_t sock_dtls_aux_rx_t
Auxiliary data provided when receiving using an DTLS sock object.
Definition dtls.h:648
sock_udp_aux_tx_t sock_dtls_aux_tx_t
Auxiliary data provided when sending using an DTLS sock object.
Definition dtls.h:658
void sock_dtls_session_get_udp_ep(const sock_dtls_session_t *session, sock_udp_ep_t *ep)
Get the remote UDP endpoint from a session.
void sock_dtls_session_set_udp_ep(sock_dtls_session_t *session, const sock_udp_ep_t *ep)
Set the remote UDP endpoint from a session.
ssize_t sock_dtls_sendv_aux(sock_dtls_t *sock, sock_dtls_session_t *remote, const iolist_t *snips, uint32_t timeout, sock_dtls_aux_tx_t *aux)
Encrypts and sends a message to a remote peer with non-continuous payload.
@ SOCK_DTLS_1_0
DTLS version 1.0.
Definition dtls.h:606
@ SOCK_DTLS_1_2
DTLS version 1.2.
Definition dtls.h:607
@ SOCK_DTLS_1_3
DTLS version 1.3.
Definition dtls.h:608
@ SOCK_DTLS_CLIENT
Endpoint client role.
Definition dtls.h:618
@ SOCK_DTLS_SERVER
Endpoint server role.
Definition dtls.h:619
struct _sock_tl_ep sock_udp_ep_t
An end point for a UDP sock object.
Definition udp.h:295
struct iolist iolist_t
iolist forward declaration
Definition iolist.h:33
UDP sock definitions.
Common sock API definitions.
tinydtls-specific types and functions definitions
Information about remote client connected to the server.
Information about DTLS sock.
Auxiliary data provided when receiving using an UDP sock object.
Definition udp.h:312
Auxiliary data provided when sending using an UDP sock object.
Definition udp.h:351