DeterministicESPAsyncWebServer v6.28.0
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
tls_policy.h
Go to the documentation of this file.
1// Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4/**
5 * @file tls_policy.h
6 * @brief TLS version negotiation + pinned cipher-suite policy (DETWS_ENABLE_TLS_POLICY).
7 *
8 * The transport TLS layer (`network_drivers/tls`, mbedTLS-backed) already runs the record and handshake
9 * and floors the version at TLS 1.2 - so both TLS 1.2 (RFC 5246) and TLS 1.3 (RFC 8446) are negotiated.
10 * What the roadmap's TLS items add on top is a *policy*: pin the negotiated version to an audited
11 * [min,max] range and make the chosen version observable, and pin the cipher suites to an audited
12 * allowlist selected by server preference (AEAD-only for a hardened profile).
13 *
14 * This is that pure policy core: `detws_tls_negotiate_version` picks the version the way a server does
15 * (the highest it supports not above the client's), `detws_tls_version_name` names it for a status
16 * endpoint, `detws_tls_select_cipher` selects a suite by server preference from the offered set, and
17 * `detws_tls_is_aead` classifies a suite. Pure, host-testable; the app feeds the results to the mbedTLS
18 * config. No heap, no stdlib.
19 */
20
21#ifndef DETERMINISTICESPASYNCWEBSERVER_TLS_POLICY_H
22#define DETERMINISTICESPASYNCWEBSERVER_TLS_POLICY_H
23
24#include "ServerConfig.h"
25#include <stddef.h>
26#include <stdint.h>
27
28#if DETWS_ENABLE_TLS_POLICY
29
30/** @brief TLS protocol version wire words. */
31#define TLS_VERSION_1_2 0x0303
32#define TLS_VERSION_1_3 0x0304
33
34/**
35 * @brief Negotiate the TLS version like a server: the highest supported that is not above the client's.
36 * @param client_max the client's highest offered version.
37 * @param server_min / @param server_max the server's supported range.
38 * @return the chosen version word, or 0 if there is no overlap (client too old).
39 */
40uint16_t detws_tls_negotiate_version(uint16_t client_max, uint16_t server_min, uint16_t server_max);
41
42/** @brief A human name for a version word: "TLS 1.2", "TLS 1.3", or "unknown". */
43const char *detws_tls_version_name(uint16_t version);
44
45/**
46 * @brief Select a cipher suite by server preference: the first suite in @p server_pinned (ordered by
47 * preference) that also appears in @p client_offered.
48 * @return the selected suite id, or 0 if none of the pinned suites was offered.
49 */
50uint16_t detws_tls_select_cipher(const uint16_t *client_offered, size_t n_client, const uint16_t *server_pinned,
51 size_t n_server);
52
53/** @brief True if @p suite is one of the modern AEAD suites (GCM / ChaCha20-Poly1305). */
54bool detws_tls_is_aead(uint16_t suite);
55
56#endif // DETWS_ENABLE_TLS_POLICY
57#endif // DETERMINISTICESPASYNCWEBSERVER_TLS_POLICY_H
User-facing configuration for DeterministicESPAsyncWebServer.