SensESP 3.0.1
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
http_authenticator.h
Go to the documentation of this file.
1#ifndef SENSESP_SRC_SENSESP_NET_HTTP_AUTHENTICATOR_H_
2#define SENSESP_SRC_SENSESP_NET_HTTP_AUTHENTICATOR_H_
3
4#include "sensesp.h"
5
6#include <esp_http_server.h>
7#include <list>
8#include <mbedtls/base64.h>
9
10#include "sensesp/system/hash.h"
11
12namespace sensesp {
13
15
21 public:
33 virtual bool authenticate_request(httpd_req_t* req) = 0;
34};
35
36struct NonceData {
37 String nonce;
38 int count;
39};
40
46 public:
47 HTTPDigestAuthenticator(String username, String password, String realm,
48 unsigned long nonce_max_age = 900000)
50 username_(username),
51 password_(password),
52 realm_(realm),
53 nonce_max_age_(nonce_max_age) {
55 }
56
57 virtual bool authenticate_request(httpd_req_t* req) override;
58
59 int authenticate_digest(httpd_req_t* req);
60
61 protected:
62 esp_err_t request_authentication(httpd_req_t* req, bool stale = false);
63
64 String username_;
65 String password_;
66 String realm_;
67 unsigned long nonce_max_age_;
68 String secret_;
70 std::list<NonceData> nonces_;
71
72 String create_nonce();
73
84 int find_nonce(String nonce, int count);
85
86 String extract_param(String param, String auth_str, bool quoted = true);
87};
88
89} // namespace sensesp
90
91#endif // SENSESP_SRC_SENSESP_NET_HTTP_AUTHENTICATOR_H_
HTTP Authenticator base class.
virtual bool authenticate_request(httpd_req_t *req)=0
Authenticate an incoming request.
HTTP Digest Authenticator class.
int authenticate_digest(httpd_req_t *req)
int find_nonce(String nonce, int count)
Find a nonce in the list of nonces.
virtual bool authenticate_request(httpd_req_t *req) override
Authenticate an incoming request.
esp_err_t request_authentication(httpd_req_t *req, bool stale=false)
HTTPDigestAuthenticator(String username, String password, String realm, unsigned long nonce_max_age=900000)
String extract_param(String param, String auth_str, bool quoted=true)
String get_random_hex_string()