SensESP 3.3.0
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 realm_(realm),
52 nonce_max_age_(nonce_max_age) {
53 ha1_ = MD5(username + ":" + realm + ":" + password);
55 }
56
58 struct PrecomputedHA1 {};
59 HTTPDigestAuthenticator(PrecomputedHA1, String username, String ha1,
60 String realm,
61 unsigned long nonce_max_age = 900000)
63 username_(username),
64 ha1_(ha1),
65 realm_(realm),
66 nonce_max_age_(nonce_max_age) {
68 }
69
70 virtual bool authenticate_request(httpd_req_t* req) override;
71
72 int authenticate_digest(httpd_req_t* req);
73
74 protected:
75 esp_err_t request_authentication(httpd_req_t* req, bool stale = false);
76
77 String username_;
78 String ha1_;
79 String realm_;
80 unsigned long nonce_max_age_;
81 String secret_;
83 std::list<NonceData> nonces_;
84
85 String create_nonce();
86
97 int find_nonce(String nonce, int count);
98
99 String extract_param(String param, String auth_str, bool quoted = true);
100};
101
102} // namespace sensesp
103
104#endif // SENSESP_SRC_SENSESP_NET_HTTP_AUTHENTICATOR_H_
virtual bool authenticate_request(httpd_req_t *req)=0
Authenticate an incoming request.
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)
HTTPDigestAuthenticator(PrecomputedHA1, String username, String ha1, String realm, unsigned long nonce_max_age=900000)
String extract_param(String param, String auth_str, bool quoted=true)
String ha1_
Pre-computed MD5(username:realm:password).
String MD5(const String &payload_str)
MD5 hash function.
Definition hash.cpp:45
String get_random_hex_string()
Construct with a pre-computed HA1 hash (avoids storing plaintext password).