DeterministicESPAsyncWebServer v6.27.1
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
spnego.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 spnego.h
6 * @brief SPNEGO (RFC 4178) GSS-API wrapping of the NTLMSSP tokens for the SMB2 client
7 * (DETWS_ENABLE_SMB).
8 *
9 * SMB2 SESSION_SETUP carries the NTLM handshake tokens inside a SPNEGO negotiation token. This is
10 * the minimal ASN.1 DER layer that a client needs:
11 * - the first client token is a GSS-API InitialContextToken: `[APPLICATION 0] { SPNEGO-OID,
12 * NegTokenInit [0] { mechTypes [0] { NTLM-OID }, mechToken [2] OCTET STRING(NTLMSSP NEGOTIATE) } }`;
13 * - the server replies with a bare NegTokenResp `[1] { ..., responseToken [2] OCTET STRING(NTLMSSP
14 * CHALLENGE) }`, from which the client extracts the CHALLENGE;
15 * - the client's second token is a NegTokenResp `[1] { responseToken [2] OCTET STRING(NTLMSSP
16 * AUTHENTICATE) }`.
17 *
18 * Pure DER, zero heap, definite-length only. The NTLM tokens come from ntlmssp.h.
19 *
20 * @author Douglas Quigg (dstroy0)
21 * @date 2026
22 */
23
24#ifndef DETERMINISTICESPASYNCWEBSERVER_SPNEGO_H
25#define DETERMINISTICESPASYNCWEBSERVER_SPNEGO_H
26
27#include "ServerConfig.h"
28
29#if DETWS_ENABLE_SMB
30
31#include <stddef.h>
32#include <stdint.h>
33
34/**
35 * @brief Wrap an NTLMSSP NEGOTIATE token in a SPNEGO GSS-API InitialContextToken (the first
36 * SESSION_SETUP security buffer).
37 * @return the token length written to @p out, or 0 on overflow.
38 */
39size_t spnego_wrap_negotiate(const uint8_t *ntlm, size_t ntlm_len, uint8_t *out, size_t cap);
40
41/**
42 * @brief Extract the responseToken (the NTLMSSP CHALLENGE) from a server NegTokenResp.
43 * @param resp_token receives a pointer INTO @p blob; @p resp_len its length.
44 * @return true if a `[2]` responseToken OCTET STRING was found and is within bounds.
45 */
46bool spnego_parse_response(const uint8_t *blob, size_t len, const uint8_t **resp_token, size_t *resp_len);
47
48/**
49 * @brief Wrap an NTLMSSP AUTHENTICATE token in a SPNEGO NegTokenResp (the second SESSION_SETUP
50 * security buffer).
51 * @return the token length written to @p out, or 0 on overflow.
52 */
53size_t spnego_wrap_authenticate(const uint8_t *ntlm, size_t ntlm_len, uint8_t *out, size_t cap);
54
55#endif // DETWS_ENABLE_SMB
56
57#endif // DETERMINISTICESPASYNCWEBSERVER_SPNEGO_H
User-facing configuration for DeterministicESPAsyncWebServer.