35#ifndef PROTOCORE_DTLS_CONN_H
36#define PROTOCORE_DTLS_CONN_H
40#if PROTOCORE_ENABLE_DTLS
55#define PROTOCORE_DTLS_CONN_REASM_CAP 1024
59#define PROTOCORE_DTLS_CONN_MSG_CAP 1024
62#define PROTOCORE_DTLS_PEER_ADDR_MAX 18
67#define PROTOCORE_DTLS_CONN_LOCAL_CID_LEN 4
71#define PROTOCORE_DTLS_FLIGHT_MSGS 16
76#define PROTOCORE_DTLS_REC_OVERHEAD_MAX (1 + PROTOCORE_DTLS_CID_MAX + 2 + 2 + PROTOCORE_DTLS_TAG_LEN)
80#define PROTOCORE_DTLS_FLIGHT_CAP (PROTOCORE_DTLS_CONN_MSG_CAP + 512)
84#define PROTOCORE_DTLS_PTO_INITIAL_MS 1000u
85#define PROTOCORE_DTLS_PTO_MAX_MS 60000u
86#define PROTOCORE_DTLS_MAX_RETRANSMITS 8
99 DTLS_CONN_STATE_START,
100 DTLS_CONN_STATE_WAIT_FINISHED,
101 DTLS_CONN_STATE_DONE,
102 DTLS_CONN_STATE_FAILED
114 const uint8_t *cert_der;
116 const uint8_t *ed25519_seed;
117 const uint8_t *ephemeral_priv;
118 const uint8_t *server_random;
119 const uint8_t *cookie_key;
126 DtlsServerConfig cfg;
143 embed_bool ep2_ready;
144 embed_bool ep3_ready;
145 uint8_t hs_finished_hash[TLS13_SECRET_MAX];
152 uint16_t next_recv_msg_seq;
156 embed_bool hs_ack_sent;
157 uint8_t peer_addr[PROTOCORE_DTLS_PEER_ADDR_MAX];
158 uint8_t peer_addr_len;
161 embed_bool cid_negotiated;
164 uint8_t peer_cid_len;
167 uint8_t local_cid_len;
171 DtlsFlightMsg flight_msgs[PROTOCORE_DTLS_FLIGHT_MSGS];
173 flight_rec[PROTOCORE_DTLS_FLIGHT_MSGS];
174 uint8_t flight_count;
176 embed_bool awaiting_reply;
180 uint32_t flight_sent_ms;
183 uint8_t reasm_buf[4 + PROTOCORE_DTLS_CONN_REASM_CAP];
184 uint8_t msgbuf[PROTOCORE_DTLS_CONN_MSG_CAP];
186 flight_buf[PROTOCORE_DTLS_FLIGHT_CAP];
193 const DtlsServerConfig *cfg;
194 const uint8_t *peer_addr;
195 size_t peer_addr_len;
202 const uint8_t *dgram;
206} DtlsServerProcessArgs;
212} DtlsServerTimeoutMsArgs;
220} DtlsServerOnTimeoutArgs;
226} DtlsServerEstablishedArgs;
232} DtlsServerAlertArgs;
238} DtlsServerAppWriteKeysArgs;
244} DtlsServerAppReadKeysArgs;
251} DtlsServerLocalCidArgs;
262} DtlsServerOpenAppArgs;
272} DtlsServerSealAppArgs;
319 DtlsServerInitArgs init_args;
320 DtlsServerProcessArgs process_args;
321 DtlsServerTimeoutMsArgs timeout_ms_args;
322 DtlsServerOnTimeoutArgs on_timeout_args;
323 DtlsServerEstablishedArgs established_args;
324 DtlsServerAlertArgs alert_args;
325 DtlsServerAppWriteKeysArgs app_write_keys_args;
326 DtlsServerAppReadKeysArgs app_read_keys_args;
327 DtlsServerLocalCidArgs local_cid_args;
328 DtlsServerOpenAppArgs open_app_args;
329 DtlsServerSealAppArgs seal_app_args;
337extern DtlsServerVars DtlsServerV;
342 void (*
const init)(
const uint8_t *work);
343 void (*
const process)(uint8_t *work);
344 void (*
const timeout_ms)(
const uint8_t *work);
345 void (*
const on_timeout)(uint8_t *work);
346 void (*
const established)(
const uint8_t *work);
347 void (*
const alert)(
const uint8_t *work);
348 void (*
const app_write_keys)(
const uint8_t *work);
349 void (*
const app_read_keys)(
const uint8_t *work);
350 void (*
const local_cid)(
const uint8_t *work);
351 void (*
const open_app)(
const uint8_t *work);
352 void (*
const seal_app)(
const uint8_t *work);
357void protocore_dtls_server_init(
const uint8_t *work);
358void protocore_dtls_server_process(uint8_t *work);
359void protocore_dtls_server_timeout_ms(
const uint8_t *work);
360void protocore_dtls_server_on_timeout(uint8_t *work);
361void protocore_dtls_server_established(
const uint8_t *work);
362void protocore_dtls_server_alert(
const uint8_t *work);
363void protocore_dtls_server_app_write_keys(
const uint8_t *work);
364void protocore_dtls_server_app_read_keys(
const uint8_t *work);
365void protocore_dtls_server_local_cid(
const uint8_t *work);
366void protocore_dtls_server_open_app(
const uint8_t *work);
367void protocore_dtls_server_seal_app(
const uint8_t *work);
373static const DtlsConnNs DtlsServer __attribute__((unused)) = {
374 .init = protocore_dtls_server_init,
375 .process = protocore_dtls_server_process,
376 .timeout_ms = protocore_dtls_server_timeout_ms,
377 .on_timeout = protocore_dtls_server_on_timeout,
378 .established = protocore_dtls_server_established,
379 .alert = protocore_dtls_server_alert,
380 .app_write_keys = protocore_dtls_server_app_write_keys,
381 .app_read_keys = protocore_dtls_server_app_read_keys,
382 .local_cid = protocore_dtls_server_local_cid,
383 .open_app = protocore_dtls_server_open_app,
384 .seal_app = protocore_dtls_server_seal_app,
EMBED_ENUM_BYTE(ProtoConn, PROTO_NONE=0, PROTO_HTTP=1, PROTO_TELNET=2, PROTO_SSH=3, PROTO_MODBUS=4, PROTO_OPCUA=5, PROTO_SSH_RFWD=6, PROTO_RELAY=7, PROTO_BRIDGE=8, PROTO_NTRIP_CASTER=9, PROTO_MESH=10, PROTO_UDP=11,)
Application protocol spoken on a listener port or connection slot.
DTLS 1.3 handshake framing and reliability (RFC 9147 §5, §7).
DTLS 1.3 record layer (RFC 9147 §4).
#define PROTOCORE_DTLS_CID_MAX
Largest connection id carried in a DTLSCiphertext header (RFC 9146 / RFC 9147 §9)....
#define PROTOCORE_SHA512_BORROW
#define PROTOCORE_TLS13_KS_BORROW
#define PROTOCORE_HMAC_SHA256_BORROW
#define PROTOCORE_TLS13_TRANSCRIPT_BORROW
TLS 1.3 key schedule (RFC 8446 sec 7.1) for the QUIC handshake.
Reassembles the fragments of a single handshake message into a contiguous body.
One direction's record-protection keys for one epoch (RFC 9147 §4).
A record identified for acknowledgement: (epoch, sequence_number), 8 bytes each on the wire (RFC 9147...
64-record sliding replay window over the highest sequence number accepted in an epoch.