/* SPDX-License-Identifier: GPL-3.0-only */ /* Persistent SSH host identity, separate from the HTTPS certificate key. */ #pragma once #include #include #include #include "esp_err.h" #ifdef __cplusplus extern "C" { #endif #define SSH_SECURITY_NVS_NAMESPACE "ssh_sec" #define SSH_SECURITY_NVS_BLOB_KEY "material" #define SSH_SECURITY_PRIVATE_KEY_DER_CAPACITY 256U #define SSH_SECURITY_SHA256_LENGTH 32U #define SSH_SECURITY_KEY_TYPE "ecdsa-sha2-nistp256" #define SSH_SECURITY_CURVE_NAME "nistp256" typedef enum { SSH_SECURITY_LOAD_STORED = 0, SSH_SECURITY_LOAD_GENERATED_MISSING = 1, } ssh_security_load_result_t; typedef struct { uint32_t generation; uint8_t sha256_fingerprint[SSH_SECURITY_SHA256_LENGTH]; } ssh_security_metadata_t; /* NVS and secure_random must be ready. Existing malformed material is not replaced. */ esp_err_t ssh_security_init(ssh_security_load_result_t *load_result); /* Query with output NULL/capacity zero; the required length is always returned. */ esp_err_t ssh_security_copy_private_key(uint8_t *output, size_t capacity, size_t *output_length); esp_err_t ssh_security_get_metadata(ssh_security_metadata_t *metadata); typedef struct { ssh_security_metadata_t metadata; bool busy; } ssh_security_identity_snapshot_t; /* Zero-wait atomic public projection; no private material. */ esp_err_t ssh_security_get_identity_snapshot(ssh_security_identity_snapshot_t *snapshot); /* Owner transaction: nonreused token, reserve before side effects and retain through * restart. Only the reserving task may replace once and release. Zero generation * selects canonical semantics; reset additionally permits unavailable material. */ esp_err_t ssh_security_reserve_identity(uint32_t generation, bool reset, uint32_t *token); esp_err_t ssh_security_replace_reserved(uint32_t token); void ssh_security_release_identity(uint32_t token); /* Rotation requires valid live material; reset replaces any stored state. * Direct callers share the reservation but do not restart the transport. */ esp_err_t ssh_security_rotate(void); esp_err_t ssh_security_reset(void); #ifdef __cplusplus } #endif