#pragma once #include #include "esp_http_server.h" #define CAM_AUTH_REALM "ESP32-Cam" typedef enum { CAM_AUTH_OK = 0, CAM_AUTH_BAD_CURRENT, /* current user name / password is wrong */ CAM_AUTH_BAD_NEW, /* new user name / password breaks the rules */ CAM_AUTH_STORE_FAILED /* could not write to flash */ } cam_auth_result_t; cam_auth_result_t cam_auth_set(const char *new_user, const char *new_pass); /* Call once at boot, before Wi-Fi/portal and servers: loads the login stored in flash, * or uses the given defaults when nothing was stored yet. */ void cam_auth_load(const char *default_user, const char *default_pass); /* True when user + password match the current login. */ bool cam_auth_verify(const char *user, const char *pass); /* Changes the login after checking the current one, and stores it in flash. * New user: 3-31 chars (letters, digits . _ -). New password: 8-32 letters/digits. */ cam_auth_result_t cam_auth_change(const char *old_user, const char *old_pass, const char *new_user, const char *new_pass); /* Set the single account used by every service (RTSP, /pic, /stream, /mic, /spk, /vol). * user NULL or "" disables authentication completely. * Use letters and digits only in the password, it also travels inside URLs. */ void cam_auth_init(const char *user, const char *pass); bool cam_auth_enabled(void); /* ---------- HTTP ---------- * Accepts either "Authorization: Basic ..." or "?key=" in the URL. * On failure it sends 401 itself and returns false, so a handler does: * if (!cam_http_check(req)) return ESP_OK; */ bool cam_http_check(httpd_req_t *req); /* ---------- RTSP (Digest, MD5, no qop) ---------- */ void cam_rtsp_make_nonce(char out[33]); bool cam_rtsp_digest_ok(const char *method, const char *authz_header_value, const char *nonce);