DeterministicESPAsyncWebServer
v6.27.1
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
snmp_v3.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 snmp_v3.h
6
* @brief SNMPv3 User-based Security Model (USM) layer (DETWS_ENABLE_SNMP_V3).
7
*
8
* Adds authenticated and optionally encrypted SNMPv3 on top of the v1/v2c agent:
9
* the v3 message framing (RFC 3412), engine discovery + timeliness (RFC 3414),
10
* USM authentication and privacy. The decrypted, authenticated inner PDU is
11
* dispatched through the shared MIB core ([`snmp_dispatch_pdu()`](@ref snmp_dispatch_pdu)),
12
* so v1/v2c and v3 expose the same objects.
13
*
14
* Protocols implemented (a single authPriv user):
15
* - **Auth:** `usmHMAC192SHA256` (HMAC-SHA-256, 24-byte digest; RFC 7860) - net-snmp `-a SHA-256`.
16
* - **Priv:** `usmAesCfb128` (AES-128-CFB; RFC 3826) - net-snmp `-x AES`.
17
*
18
* The agent is the authoritative engine, so the per-user localized keys are
19
* derived once in snmp_v3_set_user() (no per-request 1 MB key expansion).
20
*/
21
22
#ifndef DETERMINISTICESPASYNCWEBSERVER_SNMP_V3_H
23
#define DETERMINISTICESPASYNCWEBSERVER_SNMP_V3_H
24
25
#include "
ServerConfig.h
"
26
#include <stddef.h>
27
#include <stdint.h>
28
29
#if DETWS_ENABLE_SNMP_V3
30
31
/** @brief usmHMAC192SHA256 authentication-parameter length (192-bit truncation). */
32
#define SNMP_V3_AUTH_PARAM_LEN 24
33
/** @brief usmAesCfb128 privacy-parameter (salt) length. */
34
#define SNMP_V3_PRIV_PARAM_LEN 8
35
36
/**
37
* @brief Reset the v3 layer and set the authoritative engine ID.
38
*
39
* Pass nullptr to keep the built-in default engine ID. Call before
40
* snmp_v3_set_user() (the localized keys depend on the engine ID). For a unique
41
* per-device ID, derive @p id from the chip MAC.
42
*/
43
void
snmp_v3_init(
const
uint8_t *engine_id =
nullptr
,
size_t
engine_id_len = 0);
44
45
/**
46
* @brief Configure the (single) USM user and derive its localized keys.
47
*
48
* @param user user name.
49
* @param auth_pass authentication password (>= 8 chars); nullptr/empty = no auth user.
50
* @param priv_pass privacy password (>= 8 chars); nullptr/empty = auth-only (no privacy).
51
*/
52
void
snmp_v3_set_user(
const
char
*user,
const
char
*auth_pass,
const
char
*priv_pass);
53
54
/**
55
* @brief Set the persisted engineBoots counter (load from NVS, increment per boot).
56
*
57
* Timeliness (RFC 3414 §3.2) relies on a monotonically increasing boot count;
58
* the default is 1. engineTime is seconds since boot.
59
*/
60
void
snmp_v3_set_boots(uint32_t boots);
61
62
/** @brief Current authoritative engineBoots (for persisting back to NVS). */
63
uint32_t snmp_v3_get_boots();
64
65
/**
66
* @brief Process one SNMPv3 message and build the response (called by the agent).
67
*
68
* Handles engine discovery (Report with usmStatsUnknownEngineIDs), timeliness
69
* (usmStatsNotInTimeWindows), authentication and decryption, then dispatches the
70
* inner PDU and returns an authenticated/encrypted response. Returns 0 to send
71
* nothing.
72
*/
73
size_t
snmp_v3_process(
const
uint8_t *req,
size_t
req_len, uint8_t *resp,
size_t
resp_cap);
74
75
#endif
// DETWS_ENABLE_SNMP_V3
76
77
#endif
// DETERMINISTICESPASYNCWEBSERVER_SNMP_V3_H
ServerConfig.h
User-facing configuration for DeterministicESPAsyncWebServer.
src
services
snmp
snmp_v3.h
Generated by
1.9.8