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
533
534#include <assert.h>
535#include <errno.h>
536#include <stdint.h>
537#include <stdlib.h>
538#include <sys/types.h>
539
540/* net/sock/async/types.h included by net/sock.h needs to re-typedef the
541 * `sock_dtls_t` to prevent cyclic includes */
542#if defined (__clang__)
543# pragma clang diagnostic push
544# pragma clang diagnostic ignored "-Wtypedef-redefinition"
545#endif
546
547#include "net/sock.h"
548#include "net/sock/udp.h"
549#include "net/credman.h"
550
551#ifdef __cplusplus
552extern "C" {
553#endif
554
568#ifndef CONFIG_DTLS_HANDSHAKE_BUFSIZE_EXP
569#define CONFIG_DTLS_HANDSHAKE_BUFSIZE_EXP 8
570#endif
572
576#ifndef DTLS_HANDSHAKE_BUFSIZE
577#define DTLS_HANDSHAKE_BUFSIZE (1 << CONFIG_DTLS_HANDSHAKE_BUFSIZE_EXP)
578#endif
579
583#define SOCK_DTLS_HANDSHAKE (EXDEV)
584
588#ifndef CONFIG_DTLS_FORCE_EXTENDED_MASTER_SECRET
589#define CONFIG_DTLS_FORCE_EXTENDED_MASTER_SECRET 1
590#endif
591
595#ifndef CONFIG_DTLS_FORCE_RENEGOTIATION_INFO
596#define CONFIG_DTLS_FORCE_RENEGOTIATION_INFO 1
597#endif
598
604enum {
608};
610
616enum {
619};
621
628typedef struct sock_dtls sock_dtls_t;
629
630#if defined (__clang__)
631# pragma clang diagnostic pop
632#endif
633
638
648
658
664void sock_dtls_init(void);
665
689 credman_tag_t tag, unsigned version, unsigned role);
690
701
720 sock_dtls_session_t *remote);
721
736
746 sock_udp_ep_t *ep);
747
760 const sock_udp_ep_t *ep);
761
792 void *data, size_t maxlen, uint32_t timeout,
793 sock_dtls_aux_rx_t *aux);
794
822static inline ssize_t sock_dtls_recv(sock_dtls_t *sock,
823 sock_dtls_session_t *remote,
824 void *data, size_t maxlen,
825 uint32_t timeout)
826{
827 return sock_dtls_recv_aux(sock, remote, data, maxlen, timeout, NULL);
828}
829
873 void **data, void **buf_ctx, uint32_t timeout,
874 sock_dtls_aux_rx_t *aux);
875
916static inline ssize_t sock_dtls_recv_buf(sock_dtls_t *sock,
917 sock_dtls_session_t *remote,
918 void **data, void **buf_ctx,
919 uint32_t timeout)
920{
921 return sock_dtls_recv_buf_aux(sock, remote, data, buf_ctx, timeout, NULL);
922}
923
959 const iolist_t *snips, uint32_t timeout,
960 sock_dtls_aux_tx_t *aux);
961
996static inline ssize_t sock_dtls_send_aux(sock_dtls_t *sock,
997 sock_dtls_session_t *remote,
998 const void *data, size_t len,
999 uint32_t timeout,
1000 sock_dtls_aux_tx_t *aux)
1001{
1002 const iolist_t snip = {
1003 .iol_base = (void *)data,
1004 .iol_len = len,
1005 };
1006
1007 return sock_dtls_sendv_aux(sock, remote, &snip, timeout, aux);
1008}
1009
1050static inline ssize_t sock_dtls_send(sock_dtls_t *sock,
1051 sock_dtls_session_t *remote,
1052 const void *data, size_t len,
1053 uint32_t timeout)
1054{
1055 return sock_dtls_send_aux(sock, remote, data, len, timeout, NULL);
1056}
1057
1098static inline ssize_t sock_dtls_sendv(sock_dtls_t *sock,
1099 sock_dtls_session_t *remote,
1100 const iolist_t *snips,
1101 uint32_t timeout)
1102{
1103 return sock_dtls_sendv_aux(sock, remote, snips, timeout, NULL);
1104}
1105
1119
1120#ifdef MODULE_SOCK_DTLS
1121#include "sock_dtls_types.h"
1122#endif
1123
1124#ifdef __cplusplus
1125}
1126#endif
1127
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:916
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:1098
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:996
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:1050
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:637
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:822
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:647
sock_udp_aux_tx_t sock_dtls_aux_tx_t
Auxiliary data provided when sending using an DTLS sock object.
Definition dtls.h:657
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:605
@ SOCK_DTLS_1_2
DTLS version 1.2.
Definition dtls.h:606
@ SOCK_DTLS_1_3
DTLS version 1.3.
Definition dtls.h:607
@ SOCK_DTLS_CLIENT
Endpoint client role.
Definition dtls.h:617
@ SOCK_DTLS_SERVER
Endpoint server role.
Definition dtls.h:618
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